Debian Codegraph @

examples/docs/learn-core-nats-queue-groups-queue-subscribe/main.go

raw
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/nats-io/nats.go"
7 )
8
9 func main() {
10 nc, err := nats.Connect(nats.DefaultURL)
11 if err != nil {
12 panic(err)
13 }
14 defer nc.Close()
15
16 // NATS-DOC-START
17 // Join the "packers" queue group on orders.created. Every subscriber that
18 // names the same group shares the load: each order is delivered to exactly
19 // one member. Run this in several processes to watch the load balance.
20 nc.QueueSubscribe("orders.created", "packers", func(m *nats.Msg) {
21 fmt.Printf("packer handling: %s\n", string(m.Data))
22 })
23 // NATS-DOC-END
24
25 select {}
26 }