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
| package pubsub
|
| import (
| "fmt"
| "testing"
| "time"
| )
|
| func startServer(url string) {
| pub, err := NewPublisher(url,"tcp://127.0.0.1:5005",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"),
| }
|
| pub.Publish(m1)
|
| var m2 = Message{
| Topic: Topic_Camera,
| Msg: []byte("5.34"),
| }
| pub.Publish(m2)
| }
| }()
| }
|
| func TestNewSubscriber(t *testing.T) {
| url := "tcp://0.0.0.0:4005"
| startServer(url)
|
| sub, err := NewSubscriber(url,"tcp://127.0.0.1:5005",1,[]string{ Topic_Camera },"proc")
|
| if err !=nil {
| fmt.Println("NEW SUB ERR:",err)
| }
| for msg := range sub.Recv(){
| fmt.Println("RECV PUB MSG:",msg)
| }
| }
|
|