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

Function ExampleConn_Subscribe

example_test.go:83–90  ·  view source on GitHub ↗

This Example shows an asynchronous subscriber.

()

Source from the content-addressed store, hash-verified

81
82// This Example shows an asynchronous subscriber.
83func ExampleConn_Subscribe() {
84 nc, _ := nats.Connect(nats.DefaultURL)
85 defer nc.Close()
86
87 nc.Subscribe("foo", func(m *nats.Msg) {
88 fmt.Printf("Received a message: %s\n", string(m.Data))
89 })
90}
91
92func ExampleConn_ForceReconnect() {
93 nc, _ := nats.Connect(nats.DefaultURL)

Callers

nothing calls this directly

Calls 3

ConnectMethod · 0.80
SubscribeMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected