package service import ( "basic.com/pubsub/protomsg.git" "basic.com/valib/deliver.git" "encoding/json" "fmt" "github.com/gogo/protobuf/proto" "github.com/satori/go.uuid" "io/ioutil" "time" ) const ( Url_Service_PUSH = "tcp:///tmp///webserver-2.ipc" Url_Service_PULL = "tcp:///tmp///webserver-1.ipc" ) var imgPushChan chan protomsg.Recvmsg func TestPushImgMsg() { InitService() imgData := readImgFile() fmt.Println("imgData.len:",len(imgData)) for { PushImgMsg(protomsg.Recvmsg{ Id:uuid.NewV4().String(), Addr:"", Picdata:imgData, }) fmt.Println("pushed img") time.Sleep(5*time.Second) } } func readImgFile() []byte{ filePath := "/home/user/workspace/timg.jpg" bytes, err := ioutil.ReadFile(filePath) if err !=nil { fmt.Println("Read img err:",err) } return bytes } 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("recv MSG:",rMsg) resultMap[rMsg.Cid] = rMsg } } }