MCPcopy
hub / github.com/nats-io/nats.go / ExampleSubscription_NextMsg

Function ExampleSubscription_NextMsg

example_test.go:119–130  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

117}
118
119func ExampleSubscription_NextMsg() {
120 nc, _ := nats.Connect(nats.DefaultURL)
121 defer nc.Close()
122
123 sub, _ := nc.SubscribeSync("foo")
124 m, err := sub.NextMsg(1 * time.Second)
125 if err == nil {
126 fmt.Printf("Received a message: %s\n", string(m.Data))
127 } else {
128 fmt.Println("NextMsg timed out.")
129 }
130}
131
132func ExampleSubscription_Unsubscribe() {
133 nc, _ := nats.Connect(nats.DefaultURL)

Callers

nothing calls this directly

Calls 4

ConnectMethod · 0.80
NextMsgMethod · 0.80
SubscribeSyncMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected