package main import ( pb "app.yhyue.com/BP/queued/proto" "app.yhyue.com/BP/queued/util" "github.com/golang/protobuf/proto" "log" "math/rand" "time" ) const ( address = "127.0.0.1:8080" ) var ( sendPool = make(chan *pb.PubReq, 50) recivePool = make(chan *pb.PubReq, 50) ) func makeData() []float32 { ret := make([]float32, 0, 0) for i := 0; i < 10; i++ { ret = append(ret, rand.Float32()) } return ret } func main() { pub := util.NewPublisher(address, "syslog", sendPool) rec := util.NewReciver(address, "syslog", recivePool) go pub.Run() go rec.Run() //发送消息 go func() { for { param := pb.ClfReq{Item: makeData()} reqParam, _ := proto.Marshal(¶m) time.Sleep(2 * time.Second) sendPool <- &pb.PubReq{ PublishType: 2, Param: reqParam, } } }() //接受消息 for { select { case msg := <-recivePool: log.Println(msg) } } }