-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 828 Bytes
/
main.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
package main
import (
"log"
"github.com/nats-io/nats.go"
"github.com/nats-io/stan.go"
stand "github.com/nats-io/nats-streaming-server/server"
)
func main() {
stand.RunServer("test-cluster")
log.Println("Started NATS Streaming Server")
nc, err := nats.Connect("127.0.0.1", nats.Name("NATS Client"))
if err != nil {
log.Fatal(err)
}
log.Println("Connected to NATS!")
nc.Subscribe("hi", func(m *nats.Msg) {
log.Println("[Received]", string(m.Data))
})
nc.Publish("hi", []byte("Hello NATS!"))
sc, err := stan.Connect("test-cluster", "client-123", stan.NatsConn(nc))
if err != nil {
log.Fatal(err)
}
log.Println("Connected to STAN!")
sc.Publish("hi", []byte("Hello STAN!"))
sc.Subscribe("hi", func(m *stan.Msg){
log.Println("[Received]", string(m.Data))
}, stan.DeliverAllAvailable())
select {}
}