Debian Codegraph @

examples/docs/learn-core-nats-request-reply-respond/main.go

raw
1 package main
2
3 import "github.com/nats-io/nats.go"
4
5 func main() {
6 nc, err := nats.Connect(nats.DefaultURL)
7 if err != nil {
8 panic(err)
9 }
10 defer nc.Close()
11
12 // NATS-DOC-START
13 // The inventory service: subscribe to orders.inventory.check and answer
14 // every request by responding on the reply subject it carries.
15 nc.Subscribe("orders.inventory.check", func(m *nats.Msg) {
16 m.Respond([]byte(`{"in_stock":true,"warehouse":"us-east"}`))
17 })
18 // NATS-DOC-END
19
20 // Block so the service keeps answering.
21 select {}
22 }