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

Function ExampleOpenSubscription

pubsub/gcppubsub/example_test.go:76–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74}
75
76func ExampleOpenSubscription() {
77 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
78 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
79 ctx := context.Background()
80
81 // Your GCP credentials.
82 // See https://cloud.google.com/docs/authentication/production
83 // for more info on alternatives.
84 creds, err := gcp.DefaultCredentials(ctx)
85 if err != nil {
86 log.Fatal(err)
87 }
88
89 // Open a gRPC connection to the GCP Pub/Sub API.
90 conn, cleanup, err := gcppubsub.Dial(ctx, creds.TokenSource)
91 if err != nil {
92 log.Fatal(err)
93 }
94 defer cleanup()
95
96 // Construct a SubscriberClient using the connection.
97 subClient, err := gcppubsub.SubscriberClient(ctx, conn)
98 if err != nil {
99 log.Fatal(err)
100 }
101 defer subClient.Close()
102
103 // Construct a *pubsub.Subscription.
104 subscription, err := gcppubsub.OpenSubscriptionByPath(
105 subClient, "projects/myprojectID/subscriptions/example-subscription", nil)
106 if err != nil {
107 log.Fatal(err)
108 }
109 defer subscription.Shutdown(ctx)
110}
111
112func Example_extendingAckDeadline() {
113 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

DefaultCredentialsFunction · 0.92
DialFunction · 0.92
SubscriberClientFunction · 0.92
OpenSubscriptionByPathFunction · 0.92
CloseMethod · 0.65
ShutdownMethod · 0.65

Tested by

no test coverage detected