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
| 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)
| }
| }
|
|