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

Function ExampleConn_SubscribeSync

example_test.go:106–117  ·  view source on GitHub ↗

This Example shows a synchronous subscriber.

()

Source from the content-addressed store, hash-verified

104
105// This Example shows a synchronous subscriber.
106func ExampleConn_SubscribeSync() {
107 nc, _ := nats.Connect(nats.DefaultURL)
108 defer nc.Close()
109
110 sub, _ := nc.SubscribeSync("foo")
111 m, err := sub.NextMsg(1 * time.Second)
112 if err == nil {
113 fmt.Printf("Received a message: %s\n", string(m.Data))
114 } else {
115 fmt.Println("NextMsg timed out.")
116 }
117}
118
119func ExampleSubscription_NextMsg() {
120 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