| 174 | } |
| 175 | |
| 176 | func 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 | |
| 194 | func Example_openSubscriptionV2FromURL() { |
| 195 | // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored. |