From 2e2f869cc7c24b0e2cf2d1f6f60bc01fde327210 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 26 六月 2019 20:00:04 +0800
Subject: [PATCH] fix bug

---
 service/FaceSdkService.go |   89 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 71 insertions(+), 18 deletions(-)

diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
index d1bd50f..b9beb31 100644
--- a/service/FaceSdkService.go
+++ b/service/FaceSdkService.go
@@ -1,34 +1,87 @@
 package service
 
 import (
+	"basic.com/pubsub/protomsg.git"
 	"basic.com/valib/deliver.git"
-	"github.com/gin-gonic/gin/internal/json"
+	"encoding/json"
+	"fmt"
+	"github.com/gogo/protobuf/proto"
+	"github.com/satori/go.uuid"
+	"io/ioutil"
+	"time"
 )
 
-type ImageSource struct {
-	Id string `json:"id"`
-	Data []byte `json:"data"`
-}
 const (
-	Url_Service_PUSH = "tcp:///tmp///webserver-2.ipc"
-	Url_Service_PULL = "tcp:///tmp///webserver-1.ipc"
+	Url_Service_PUSH = "tcp:///tmp///webserver_2.ipc"
+	Url_Service_PULL = "tcp:///tmp///webserver_1.ipc"
 )
-var imgChan chan ImageSource
-func PushImgMsg(is ImageSource){
-	imgChan <- is
+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(){
-	imgChan = make(chan ImageSource)
-	client := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
-	for {
-		select {
-		case is := <- imgChan:
-			b, _ := json.Marshal(is)
-			client.Send(b)
+	fmt.Println("service init!")
+	imgPushChan = make(chan protomsg.Recvmsg)
+	client_push := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
+	client_pull := deliver.NewClient(deliver.PushPull, Url_Service_PULL)
+
+	go func() {
+		for {
+			select {
+			case is := <- imgPushChan:
+				fmt.Println("imgPushChan in")
+				b, _ := json.Marshal(is)
+				client_push.Send(b)
+			default:
+				//fmt.Println("no img in")
+			}
 		}
+	}()
 
+	go func() {
+		//鎺ユ敹浜鸿劯鎻愬彇缁撴灉
+		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
+			}
 
-	}
+		}
+	}()
 
 }
\ No newline at end of file

--
Gitblit v1.8.0