liuxiaolong
2019-06-26 021679b25d25b608380be9e50d09184a3f49eb62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package service
 
import (
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/deliver.git"
    "encoding/json"
    "fmt"
    "github.com/gogo/protobuf/proto"
)
 
const (
    Url_Service_PUSH = "tcp:///tmp///webserver-2.ipc"
    Url_Service_PULL = "tcp:///tmp///webserver-1.ipc"
)
var imgPushChan chan protomsg.Recvmsg
 
func PushImgMsg(is protomsg.Recvmsg){
    imgPushChan <- is
}
 
var resultMap map[string]protomsg.SdkMessage
 
 
func InitService(){
    imgPushChan = make(chan protomsg.Recvmsg)
    client_push := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
    client_pull := deliver.NewClient(deliver.PushPull, Url_Service_PULL)
    for {
        select {
            case is := <- imgPushChan:
                b, _ := json.Marshal(is)
                client_push.Send(b)
        }
    }
 
    //接收人脸提取结果
    for {
        resultBytes, err := client_pull.Recv()
        if err !=nil{
            fmt.Println("pull err:",err)
            continue
        }
        rMsg := protomsg.SdkMessage{}
        if err := proto.Unmarshal(resultBytes, &rMsg);err !=nil{
            fmt.Println(rMsg)
            resultMap[rMsg.Cid] = rMsg
        }
 
    }
 
}