package pubsub import ( "encoding/json" "fmt" "testing" "time" ) func startServer(url string) { pub, err := NewPublisher(url,1) if err !=nil { fmt.Println("NEW PUB ERR:",err) } go func() { for { time.Sleep(3*time.Second) var m1 = Message{ Topic: Topic_Task, Msg: []byte("tttt"), } b1, _ := json.Marshal(m1) pub.Publish(b1) var m2 = Message{ Topic: Topic_Camera, Msg: []byte("5.34"), } b2, _ := json.Marshal(m2) pub.Publish(b2) } }() } func TestNewSubscriber(t *testing.T) { url := "tcp://0.0.0.0:4005" startServer(url) sub, err := NewSubscriber(url,1,[]string{ Topic_Camera }) if err !=nil { fmt.Println("NEW SUB ERR:",err) } for msg := range sub.Recv(){ fmt.Println("RECV PUB MSG:",msg) } }