forked from gammazero/nexus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.go
64 lines (53 loc) · 1.57 KB
/
publisher.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"log"
"os"
"github.com/Suited-Entertainment/nexus/v3/examples/newclient"
"github.com/Suited-Entertainment/nexus/v3/wamp"
)
const exampleTopic = "example.hello"
func main() {
logger := log.New(os.Stdout, "PUBLISHER> ", 0)
// Connect publisher client with requested socket type and serialization.
publisher, err := newclient.NewClient(logger)
if err != nil {
logger.Fatal(err)
}
defer publisher.Close()
// Publish to topic.
args := wamp.List{"hello world"}
err = publisher.Publish(exampleTopic, nil, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
// Publish more events to topic.
args = wamp.List{"how are you today"}
err = publisher.Publish(exampleTopic, nil, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
// Publish events only to sessions 42, 1138, 1701.
args = wamp.List{"for your eyes only"}
opts := wamp.Dict{wamp.WhitelistKey: wamp.List{42, 1138, 1701}}
err = publisher.Publish(exampleTopic, opts, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
args = wamp.List{"testing 1"}
err = publisher.Publish(exampleTopic, nil, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
args = wamp.List{"testing 2"}
err = publisher.Publish(exampleTopic, nil, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
args = wamp.List{"testing 3"}
err = publisher.Publish(exampleTopic, nil, args, nil)
if err != nil {
logger.Fatalf("publish error: %s", err)
}
logger.Println("Published messages to", exampleTopic)
publisher.Close()
}