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

Function Example_openTopicFromURL

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

Source from the content-addressed store, hash-verified

85}
86
87func Example_openTopicFromURL() {
88 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
89 // PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/pubsub/natspubsub"
90 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
91 ctx := context.Background()
92
93 // pubsub.OpenTopic creates a *pubsub.Topic from a URL.
94 // This URL will Dial the NATS server at the URL in the environment variable
95 // NATS_SERVER_URL and send messages with subject "example.mysubject".
96 topic, err := pubsub.OpenTopic(ctx, "nats://example.mysubject")
97 if err != nil {
98 log.Fatal(err)
99 }
100 defer topic.Shutdown(ctx)
101}
102
103func Example_openSubscriptionFromURL() {
104 // 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