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

Function ExampleOpenSubscription

pubsub/gcppubsubv2/example_test.go:71–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69}
70
71func ExampleOpenSubscription() {
72 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
73 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
74 ctx := context.Background()
75
76 // Your GCP credentials.
77 // See https://cloud.google.com/docs/authentication/production
78 // for more info on alternatives.
79 creds, err := gcp.DefaultCredentials(ctx)
80 if err != nil {
81 log.Fatal(err)
82 }
83
84 // Open a gRPC connection to the GCP Pub/Sub API.
85 // Alternatively, skip this and pass nil to Client below to use the default.
86 conn, cleanup, err := gcppubsubv2.Dial(ctx, creds.TokenSource)
87 if err != nil {
88 log.Fatal(err)
89 }
90 defer cleanup()
91
92 // Construct a Client using the connection.
93 client, err := gcppubsubv2.Client(ctx, "myprojectID", conn)
94 if err != nil {
95 log.Fatal(err)
96 }
97 defer client.Close()
98
99 // Construct a *pubsub.Subscription.
100 subscription := gcppubsubv2.OpenSubscription(client, "example-subscription", nil)
101 defer subscription.Shutdown(ctx)
102}
103
104func Example_openSubscriptionFromURL() {
105 // 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 6

DefaultCredentialsFunction · 0.92
DialFunction · 0.92
ClientFunction · 0.92
OpenSubscriptionFunction · 0.92
CloseMethod · 0.65
ShutdownMethod · 0.65

Tested by

no test coverage detected