| 61 | } |
| 62 | |
| 63 | func 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 | |
| 79 | func Example_openSubscriptionFromURL() { |
| 80 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |