| 85 | } |
| 86 | |
| 87 | func 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 | |
| 103 | func Example_openSubscriptionFromURL() { |
| 104 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |