MCPcopy Create free account
hub / github.com/google/go-cloud / Example_openTopicV2FromURL

Function Example_openTopicV2FromURL

pubsub/natspubsub/example_test.go:176–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

174}
175
176func Example_openTopicV2FromURL() {
177 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
178 // PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/pubsub/natspubsub"
179 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
180 ctx := context.Background()
181
182 // pubsub.OpenTopic creates a *pubsub.Topic from a URL.
183 // This URL will Dial the NATS server at the URL in the environment variable
184 // NATS_SERVER_URL and send messages with subject "example.mysubject".
185 // This URL will be parsed and the natsv2 attribute will be used to
186 // use NATS v2.2.0+ native message headers as the message metadata.
187 topic, err := pubsub.OpenTopic(ctx, "nats://example.mysubject?natsv2")
188 if err != nil {
189 log.Fatal(err)
190 }
191 defer topic.Shutdown(ctx)
192}
193
194func Example_openSubscriptionV2FromURL() {
195 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.

Callers

nothing calls this directly

Calls 2

OpenTopicFunction · 0.92
ShutdownMethod · 0.65

Tested by

no test coverage detected