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

Function Example_openTopicFromURL

pubsub/kafkapubsub/example_test.go:63–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63func Example_openTopicFromURL() {
64 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
65 // PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/pubsub/kafkapubsub"
66 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
67 ctx := context.Background()
68
69 // pubsub.OpenTopic creates a *pubsub.Topic from a URL.
70 // The host + path are the topic name to send to.
71 // The set of brokers must be in an environment variable KAFKA_BROKERS.
72 topic, err := pubsub.OpenTopic(ctx, "kafka://my-topic?key_name=x-partition-key")
73 if err != nil {
74 log.Fatal(err)
75 }
76 defer topic.Shutdown(ctx)
77}
78
79func Example_openSubscriptionFromURL() {
80 // 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