Cloud Pub/Sub API v1 - Package cloud.google.com/go/pubsub/apiv1 (v1.9.1)

Package pubsub is an auto-generated package for the Cloud Pub/Sub API.

Provides reliable, many-to-many, asynchronous messaging between applications.

Use of Context

The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

For information about setting deadlines, reusing contexts, and more please visit pkg.go.dev/cloud.google.com/go.

Functions

func DefaultAuthScopes

  func 
  
 DefaultAuthScopes 
 () 
  
 [] 
  string 
 
 

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

func PublisherProjectPath (deprecated)

  func 
  
 PublisherProjectPath 
 ( 
 project 
  
  string 
 
 ) 
  
  string 
 
 

PublisherProjectPath returns the path for the project resource.

Deprecated: Use fmt.Sprintf("projects/%s", project) instead.

func PublisherTopicPath (deprecated)

  func 
  
 PublisherTopicPath 
 ( 
 project 
 , 
  
 topic 
  
  string 
 
 ) 
  
  string 
 
 

PublisherTopicPath returns the path for the topic resource.

Deprecated: Use fmt.Sprintf("projects/%s/topics/%s", project, topic) instead.

func SubscriberProjectPath (deprecated)

  func 
  
 SubscriberProjectPath 
 ( 
 project 
  
  string 
 
 ) 
  
  string 
 
 

SubscriberProjectPath returns the path for the project resource.

Deprecated: Use fmt.Sprintf("projects/%s", project) instead.

func SubscriberSnapshotPath (deprecated)

  func 
  
 SubscriberSnapshotPath 
 ( 
 project 
 , 
  
 snapshot 
  
  string 
 
 ) 
  
  string 
 
 

SubscriberSnapshotPath returns the path for the snapshot resource.

Deprecated: Use fmt.Sprintf("projects/%s/snapshots/%s", project, snapshot) instead.

func SubscriberSubscriptionPath (deprecated)

  func 
  
 SubscriberSubscriptionPath 
 ( 
 project 
 , 
  
 subscription 
  
  string 
 
 ) 
  
  string 
 
 

SubscriberSubscriptionPath returns the path for the subscription resource.

Deprecated: Use fmt.Sprintf("projects/%s/subscriptions/%s", project, subscription) instead.

func SubscriberTopicPath (deprecated)

  func 
  
 SubscriberTopicPath 
 ( 
 project 
 , 
  
 topic 
  
  string 
 
 ) 
  
  string 
 
 

SubscriberTopicPath returns the path for the topic resource.

Deprecated: Use fmt.Sprintf("projects/%s/topics/%s", project, topic) instead.

PublisherCallOptions

  type 
  
 PublisherCallOptions 
  
 struct 
  
 { 
  
 CreateTopic 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 UpdateTopic 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 Publish 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 GetTopic 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ListTopics 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ListTopicSubscriptions 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ListTopicSnapshots 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 DeleteTopic 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 DetachSubscription 
  
 [] 
  gax 
 
 . 
  CallOption 
 
 } 
 

PublisherCallOptions contains the retry settings for each method of PublisherClient.

PublisherClient

  type 
  
 PublisherClient 
  
 struct 
  
 { 
  
 // The call options for this service. 
  
 CallOptions 
  
 * 
  PublisherCallOptions 
 
  
 // contains filtered or unexported fields 
 } 
 

PublisherClient is a client for interacting with Cloud Pub/Sub API.

Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

func NewPublisherClient

  func 
  
 NewPublisherClient 
 ( 
 ctx 
  
  context 
 
 . 
  Context 
 
 , 
  
 opts 
  
 ... 
  option 
 
 . 
  ClientOption 
 
 ) 
  
 ( 
 * 
  PublisherClient 
 
 , 
  
  error 
 
 ) 
 

NewPublisherClient creates a new publisher client.

The service that an application uses to manipulate topics, and to send messages to a topic.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use client. 
  
 _ 
  
 = 
  
 c 
 } 
 

func (*PublisherClient) Close

  func 
  
 ( 
 c 
  
 * 
  PublisherClient 
 
 ) 
  
 Close 
 () 
  
  error 
 
 

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*PublisherClient) Connection

  func 
  
 ( 
 c 
  
 * 
  PublisherClient 
 
 ) 
  
 Connection 
 () 
  
 * 
  grpc 
 
 . 
  ClientConn 
 
 

Connection returns a connection to the API service.

Deprecated.

func (*PublisherClient) CreateTopic

CreateTopic creates the given topic with the given name. See the resource name rules (at https://cloud.google.com/pubsub/docs/admin#resource_names ).

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  Topic 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 CreateTopic 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*PublisherClient) DeleteTopic

DeleteTopic deletes the topic with the given name. Returns NOT_FOUND if the topic does not exist. After a topic is deleted, a new topic may be created with the same name; this is an entirely new topic with none of the old configuration or subscriptions. Existing subscriptions to this topic are not deleted, but their topic field is set to deleted-topic .

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  DeleteTopicRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 DeleteTopic 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*PublisherClient) DetachSubscription

DetachSubscription detaches a subscription from this topic. All messages retained in the subscription are dropped. Subsequent Pull and StreamingPull requests will return FAILED_PRECONDITION. If the subscription is a push subscription, pushes to the endpoint will stop.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  DetachSubscriptionRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 DetachSubscription 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*PublisherClient) GetTopic

GetTopic gets the configuration of a topic.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  GetTopicRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 GetTopic 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*PublisherClient) ListTopicSnapshots

ListTopicSnapshots lists the names of the snapshots on this topic. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 "google.golang.org/api/iterator" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 // import "google.golang.org/api/iterator" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ListTopicSnapshotsRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 it 
  
 := 
  
 c 
 . 
 ListTopicSnapshots 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*PublisherClient) ListTopicSubscriptions

ListTopicSubscriptions lists the names of the attached subscriptions on this topic.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 "google.golang.org/api/iterator" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 // import "google.golang.org/api/iterator" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ListTopicSubscriptionsRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 it 
  
 := 
  
 c 
 . 
 ListTopicSubscriptions 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*PublisherClient) ListTopics

ListTopics lists matching topics.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 "google.golang.org/api/iterator" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 // import "google.golang.org/api/iterator" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ListTopicsRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 it 
  
 := 
  
 c 
 . 
 ListTopics 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*PublisherClient) Publish

Publish adds one or more messages to the topic. Returns NOT_FOUND if the topic does not exist.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  PublishRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 Publish 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*PublisherClient) SetGoogleClientInfo

  func 
  
 ( 
 pc 
  
 * 
  PublisherClient 
 
 ) 
  
 SetGoogleClientInfo 
 ( 
 keyval 
  
  string 
 
 ) 
 

SetGoogleClientInfo sets the name and version of the application in the x-goog-api-client header passed on each request. Also passes any provided key-value pairs. Intended for use by Google-written clients.

Internal use only.

func (*PublisherClient) SubscriptionIAM

  func 
  
 ( 
 c 
  
 * 
  PublisherClient 
 
 ) 
  
 SubscriptionIAM 
 ( 
 subscription 
  
 * 
  pubsubpb 
 
 . 
  Subscription 
 
 ) 
  
 * 
  iam 
 
 . 
  Handle 
 
 

func (*PublisherClient) TopicIAM

  func 
  
 ( 
 c 
  
 * 
  PublisherClient 
 
 ) 
  
 TopicIAM 
 ( 
 topic 
  
 * 
  pubsubpb 
 
 . 
  Topic 
 
 ) 
  
 * 
  iam 
 
 . 
  Handle 
 
 

func (*PublisherClient) UpdateTopic

UpdateTopic updates an existing topic. Note that certain properties of a topic are not modifiable.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewPublisherClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  UpdateTopicRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 UpdateTopic 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

SnapshotIterator

  type 
  
 SnapshotIterator 
  
 struct 
  
 { 
  
 // Response is the raw response for the current page. 
  
 // It must be cast to the RPC response type. 
  
 // Calling Next() or InternalFetch() updates this value. 
  
 Response 
  
 interface 
 {} 
  
 // InternalFetch is for use by the Google Cloud Libraries only. 
  
 // It is not part of the stable interface of this package. 
  
 // 
  
 // InternalFetch returns results from a single call to the underlying RPC. 
  
 // The number of results is no greater than pageSize. 
  
 // If there are no more results, nextPageToken is empty and err is nil. 
  
 InternalFetch 
  
 func 
 ( 
 pageSize 
  
  int 
 
 , 
  
 pageToken 
  
  string 
 
 ) 
  
 ( 
 results 
  
 [] 
 * 
  pubsubpb 
 
 . 
  Snapshot 
 
 , 
  
 nextPageToken 
  
  string 
 
 , 
  
 err 
  
  error 
 
 ) 
  
 // contains filtered or unexported fields 
 } 
 

SnapshotIterator manages a stream of *pubsubpb.Snapshot.

func (*SnapshotIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*SnapshotIterator) PageInfo

  func 
  
 ( 
 it 
  
 * 
  SnapshotIterator 
 
 ) 
  
 PageInfo 
 () 
  
 * 
  iterator 
 
 . 
  PageInfo 
 
 

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

StringIterator

  type 
  
 StringIterator 
  
 struct 
  
 { 
  
 // Response is the raw response for the current page. 
  
 // It must be cast to the RPC response type. 
  
 // Calling Next() or InternalFetch() updates this value. 
  
 Response 
  
 interface 
 {} 
  
 // InternalFetch is for use by the Google Cloud Libraries only. 
  
 // It is not part of the stable interface of this package. 
  
 // 
  
 // InternalFetch returns results from a single call to the underlying RPC. 
  
 // The number of results is no greater than pageSize. 
  
 // If there are no more results, nextPageToken is empty and err is nil. 
  
 InternalFetch 
  
 func 
 ( 
 pageSize 
  
  int 
 
 , 
  
 pageToken 
  
  string 
 
 ) 
  
 ( 
 results 
  
 [] 
  string 
 
 , 
  
 nextPageToken 
  
  string 
 
 , 
  
 err 
  
  error 
 
 ) 
  
 // contains filtered or unexported fields 
 } 
 

StringIterator manages a stream of string.

func (*StringIterator) Next

  func 
  
 ( 
 it 
  
 * 
  StringIterator 
 
 ) 
  
 Next 
 () 
  
 ( 
  string 
 
 , 
  
  error 
 
 ) 
 

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*StringIterator) PageInfo

  func 
  
 ( 
 it 
  
 * 
  StringIterator 
 
 ) 
  
 PageInfo 
 () 
  
 * 
  iterator 
 
 . 
  PageInfo 
 
 

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

SubscriberCallOptions

  type 
  
 SubscriberCallOptions 
  
 struct 
  
 { 
  
 CreateSubscription 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 GetSubscription 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 UpdateSubscription 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ListSubscriptions 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 DeleteSubscription 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ModifyAckDeadline 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 Acknowledge 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 Pull 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 StreamingPull 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ModifyPushConfig 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 GetSnapshot 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 ListSnapshots 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 CreateSnapshot 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 UpdateSnapshot 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 DeleteSnapshot 
  
 [] 
  gax 
 
 . 
  CallOption 
 
  
 Seek 
  
 [] 
  gax 
 
 . 
  CallOption 
 
 } 
 

SubscriberCallOptions contains the retry settings for each method of SubscriberClient.

SubscriberClient

  type 
  
 SubscriberClient 
  
 struct 
  
 { 
  
 // The call options for this service. 
  
 CallOptions 
  
 * 
  SubscriberCallOptions 
 
  
 // contains filtered or unexported fields 
 } 
 

SubscriberClient is a client for interacting with Cloud Pub/Sub API.

Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

func NewSubscriberClient

  func 
  
 NewSubscriberClient 
 ( 
 ctx 
  
  context 
 
 . 
  Context 
 
 , 
  
 opts 
  
 ... 
  option 
 
 . 
  ClientOption 
 
 ) 
  
 ( 
 * 
  SubscriberClient 
 
 , 
  
  error 
 
 ) 
 

NewSubscriberClient creates a new subscriber client.

The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the Pull method or by establishing a bi-directional stream using the StreamingPull method.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use client. 
  
 _ 
  
 = 
  
 c 
 } 
 

func (*SubscriberClient) Acknowledge

Acknowledge acknowledges the messages associated with the ack_ids in the AcknowledgeRequest. The Pub/Sub system can remove the relevant messages from the subscription.

Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  AcknowledgeRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 Acknowledge 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*SubscriberClient) Close

  func 
  
 ( 
 c 
  
 * 
  SubscriberClient 
 
 ) 
  
 Close 
 () 
  
  error 
 
 

Close closes the connection to the API service. The user should invoke this when the client is no longer required.

func (*SubscriberClient) Connection

  func 
  
 ( 
 c 
  
 * 
  SubscriberClient 
 
 ) 
  
 Connection 
 () 
  
 * 
  grpc 
 
 . 
  ClientConn 
 
 

Connection returns a connection to the API service.

Deprecated.

func (*SubscriberClient) CreateSnapshot

CreateSnapshot creates a snapshot from the requested subscription. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. If the snapshot already exists, returns ALREADY_EXISTS. If the requested subscription doesn’t exist, returns NOT_FOUND. If the backlog in the subscription is too old – and the resulting snapshot would expire in less than 1 hour – then FAILED_PRECONDITION is returned. See also the Snapshot.expire_time field. If the name is not provided in the request, the server will assign a random name for this snapshot on the same project as the subscription, conforming to the [resource name format] ( https://cloud.google.com/pubsub/docs/admin#resource_names (at https://cloud.google.com/pubsub/docs/admin#resource_names )). The generated name is populated in the returned Snapshot object. Note that for REST API requests, you must specify a name in the request.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  CreateSnapshotRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 CreateSnapshot 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) CreateSubscription

CreateSubscription creates a subscription to a given topic. See the [resource name rules] ( https://cloud.google.com/pubsub/docs/admin#resource_names (at https://cloud.google.com/pubsub/docs/admin#resource_names )). If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn’t exist, returns NOT_FOUND.

If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the [resource name format] ( https://cloud.google.com/pubsub/docs/admin#resource_names (at https://cloud.google.com/pubsub/docs/admin#resource_names )). The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  Subscription 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 CreateSubscription 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) DeleteSnapshot

DeleteSnapshot removes an existing snapshot. Snapshots are used in [Seek] ( https://cloud.google.com/pubsub/docs/replay-overview (at https://cloud.google.com/pubsub/docs/replay-overview )) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. When the snapshot is deleted, all messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  DeleteSnapshotRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 DeleteSnapshot 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*SubscriberClient) DeleteSubscription

DeleteSubscription deletes an existing subscription. All messages retained in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND. After a subscription is deleted, a new one may be created with the same name, but the new one has no association with the old subscription or its topic unless the same topic is specified.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  DeleteSubscriptionRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 DeleteSubscription 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*SubscriberClient) GetSnapshot

GetSnapshot gets the configuration details of a snapshot. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  GetSnapshotRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 GetSnapshot 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) GetSubscription

GetSubscription gets the configuration details of a subscription.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  GetSubscriptionRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 GetSubscription 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) ListSnapshots

ListSnapshots lists the existing snapshots. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 "google.golang.org/api/iterator" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 // import "google.golang.org/api/iterator" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ListSnapshotsRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 it 
  
 := 
  
 c 
 . 
 ListSnapshots 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*SubscriberClient) ListSubscriptions

ListSubscriptions lists matching subscriptions.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 "google.golang.org/api/iterator" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 // import "google.golang.org/api/iterator" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ListSubscriptionsRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 it 
  
 := 
  
 c 
 . 
 ListSubscriptions 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 it 
 . 
 Next 
 () 
  
 if 
  
 err 
  
 == 
  
 iterator 
 . 
 Done 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*SubscriberClient) ModifyAckDeadline

ModifyAckDeadline modifies the ack deadline for a specific message. This method is useful to indicate that more time is needed to process a message by the subscriber, or to make the message available for redelivery if the processing was interrupted. Note that this does not modify the subscription-level ackDeadlineSeconds used for subsequent messages.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ModifyAckDeadlineRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 ModifyAckDeadline 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*SubscriberClient) ModifyPushConfig

ModifyPushConfig modifies the PushConfig for a specified subscription.

This may be used to change a push subscription to a pull one (signified by an empty PushConfig) or vice versa, or change the endpoint URL and other attributes of a push subscription. Messages will accumulate for delivery continuously through the call regardless of changes to the PushConfig.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  ModifyPushConfigRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 err 
  
 = 
  
 c 
 . 
 ModifyPushConfig 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
 } 
 

func (*SubscriberClient) Pull

Pull pulls messages from the server. The server may return UNAVAILABLE if there are too many concurrent pull requests pending for the given subscription.

Examples

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  PullRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 Pull 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 
lengthyClientProcessing
  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "log" 
  
 "time" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 projectID 
  
 := 
  
 "some-project" 
  
 subscriptionID 
  
 := 
  
 "some-subscription" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatal 
 ( 
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 sub 
  
 := 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/subscriptions/%s" 
 , 
  
 projectID 
 , 
  
 subscriptionID 
 ) 
  
 // Be sure to tune the MaxMessages parameter per your project's needs, and accordingly 
  
 // adjust the ack behavior below to batch acknowledgements. 
  
 req 
  
 := 
  
 pubsubpb 
 . 
  PullRequest 
 
 { 
  
 Subscription 
 : 
  
 sub 
 , 
  
 MaxMessages 
 : 
  
 1 
 , 
  
 } 
  
 fmt 
 . 
 Println 
 ( 
 "Listening.." 
 ) 
  
 for 
  
 { 
  
 res 
 , 
  
 err 
  
 := 
  
 client 
 . 
 Pull 
 ( 
 ctx 
 , 
  
& req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatal 
 ( 
 err 
 ) 
  
 } 
  
 // client.Pull returns an empty list if there are no messages available in the 
  
 // backlog. We should skip processing steps when that happens. 
  
 if 
  
 len 
 ( 
 res 
 . 
 ReceivedMessages 
 ) 
  
 == 
  
 0 
  
 { 
  
 continue 
  
 } 
  
 var 
  
 recvdAckIDs 
  
 [] 
 string 
  
 for 
  
 _ 
 , 
  
 m 
  
 := 
  
 range 
  
 res 
 . 
 ReceivedMessages 
  
 { 
  
 recvdAckIDs 
  
 = 
  
 append 
 ( 
 recvdAckIDs 
 , 
  
 m 
 . 
 AckId 
 ) 
  
 } 
  
 var 
  
 done 
  
 = 
  
 make 
 ( 
 chan 
  
 struct 
 {}) 
  
 var 
  
 delay 
  
 = 
  
 0 
  
 * 
  
 time 
 . 
 Second 
  
 // Tick immediately upon reception 
  
 var 
  
 ackDeadline 
  
 = 
  
 10 
  
 * 
  
 time 
 . 
 Second 
  
 // Continuously notify the server that processing is still happening on this batch. 
  
 go 
  
 func 
 () 
  
 { 
  
 for 
  
 { 
  
 select 
  
 { 
  
 case 
  
< - 
 ctx 
 . 
 Done 
 (): 
  
 return 
  
 case 
  
< - 
 done 
 : 
  
 return 
  
 case 
  
< - 
 time 
 . 
 After 
 ( 
 delay 
 ): 
  
 err 
  
 := 
  
 client 
 . 
 ModifyAckDeadline 
 ( 
 ctx 
 , 
  
& pubsubpb 
 . 
  ModifyAckDeadlineRequest 
 
 { 
  
 Subscription 
 : 
  
 sub 
 , 
  
 AckIds 
 : 
  
 recvdAckIDs 
 , 
  
 AckDeadlineSeconds 
 : 
  
 int32 
 ( 
 ackDeadline 
 . 
 Seconds 
 ()), 
  
 }) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatal 
 ( 
 err 
 ) 
  
 } 
  
 delay 
  
 = 
  
 ackDeadline 
  
 - 
  
 5 
 * 
 time 
 . 
 Second 
  
 // 5 seconds grace period. 
  
 } 
  
 } 
  
 }() 
  
 for 
  
 _ 
 , 
  
 m 
  
 := 
  
 range 
  
 res 
 . 
 ReceivedMessages 
  
 { 
  
 // Process the message here, possibly in a goroutine. 
  
 log 
 . 
 Printf 
 ( 
 "Got message: %s" 
 , 
  
 string 
 ( 
 m 
 . 
 Message 
 . 
 Data 
 )) 
  
 err 
  
 := 
  
 client 
 . 
 Acknowledge 
 ( 
 ctx 
 , 
  
& pubsubpb 
 . 
  AcknowledgeRequest 
 
 { 
  
 Subscription 
 : 
  
 sub 
 , 
  
 AckIds 
 : 
  
 [] 
 string 
 { 
 m 
 . 
 AckId 
 }, 
  
 }) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatal 
 ( 
 err 
 ) 
  
 } 
  
 } 
  
 close 
 ( 
 done 
 ) 
  
 } 
 } 
 

func (*SubscriberClient) Seek

Seek seeks an existing subscription to a point in time or to a given snapshot, whichever is provided in the request. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. Note that both the subscription and the snapshot must be on the same topic.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  SeekRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 Seek 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) SetGoogleClientInfo

  func 
  
 ( 
 sc 
  
 * 
  SubscriberClient 
 
 ) 
  
 SetGoogleClientInfo 
 ( 
 keyval 
  
  string 
 
 ) 
 

SetGoogleClientInfo sets the name and version of the application in the x-goog-api-client header passed on each request. Also passes any provided key-value pairs. Intended for use by Google-written clients.

Internal use only.

func (*SubscriberClient) StreamingPull

StreamingPull establishes a stream with the server, which sends messages down to the client. The client streams acknowledgements and ack deadline modifications back to the server. The server will close the stream and return the status on any error. The server may close the stream with status UNAVAILABLE to reassign server-side resources, in which case, the client should re-establish the stream. Flow control can be achieved by configuring the underlying RPC channel.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 "io" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 stream 
 , 
  
 err 
  
 := 
  
 c 
 . 
 StreamingPull 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 go 
  
 func 
 () 
  
 { 
  
 reqs 
  
 := 
  
 [] 
 * 
 pubsubpb 
 . 
  StreamingPullRequest 
 
 { 
  
 // TODO: Create requests. 
  
 } 
  
 for 
  
 _ 
 , 
  
 req 
  
 := 
  
 range 
  
 reqs 
  
 { 
  
 if 
  
 err 
  
 := 
  
 stream 
 . 
 Send 
 ( 
 req 
 ); 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 } 
  
 stream 
 . 
 CloseSend 
 () 
  
 }() 
  
 for 
  
 { 
  
 resp 
 , 
  
 err 
  
 := 
  
 stream 
 . 
 Recv 
 () 
  
 if 
  
 err 
  
 == 
  
 io 
 . 
 EOF 
  
 { 
  
 break 
  
 } 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
  
 } 
 } 
 

func (*SubscriberClient) SubscriptionIAM

  func 
  
 ( 
 c 
  
 * 
  SubscriberClient 
 
 ) 
  
 SubscriptionIAM 
 ( 
 subscription 
  
 * 
  pubsubpb 
 
 . 
  Subscription 
 
 ) 
  
 * 
  iam 
 
 . 
  Handle 
 
 

func (*SubscriberClient) TopicIAM

  func 
  
 ( 
 c 
  
 * 
  SubscriberClient 
 
 ) 
  
 TopicIAM 
 ( 
 topic 
  
 * 
  pubsubpb 
 
 . 
  Topic 
 
 ) 
  
 * 
  iam 
 
 . 
  Handle 
 
 

func (*SubscriberClient) UpdateSnapshot

UpdateSnapshot updates an existing snapshot. Snapshots are used in Seek (at https://cloud.google.com/pubsub/docs/replay-overview ) operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  UpdateSnapshotRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 UpdateSnapshot 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

func (*SubscriberClient) UpdateSubscription

UpdateSubscription updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable.

Example

  package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 pubsub 
  
 "cloud.google.com/go/pubsub/apiv1" 
  
 pubsubpb 
  
 "google.golang.org/genproto/googleapis/pubsub/v1" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 // import pubsubpb "google.golang.org/genproto/googleapis/pubsub/v1" 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 c 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewSubscriberClient 
 ( 
 ctx 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 req 
  
 := 
  
& pubsubpb 
 . 
  UpdateSubscriptionRequest 
 
 { 
  
 // TODO: Fill request struct fields. 
  
 } 
  
 resp 
 , 
  
 err 
  
 := 
  
 c 
 . 
 UpdateSubscription 
 ( 
 ctx 
 , 
  
 req 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 // TODO: Handle error. 
  
 } 
  
 // TODO: Use resp. 
  
 _ 
  
 = 
  
 resp 
 } 
 

SubscriptionIterator

  type 
  
 SubscriptionIterator 
  
 struct 
  
 { 
  
 // Response is the raw response for the current page. 
  
 // It must be cast to the RPC response type. 
  
 // Calling Next() or InternalFetch() updates this value. 
  
 Response 
  
 interface 
 {} 
  
 // InternalFetch is for use by the Google Cloud Libraries only. 
  
 // It is not part of the stable interface of this package. 
  
 // 
  
 // InternalFetch returns results from a single call to the underlying RPC. 
  
 // The number of results is no greater than pageSize. 
  
 // If there are no more results, nextPageToken is empty and err is nil. 
  
 InternalFetch 
  
 func 
 ( 
 pageSize 
  
  int 
 
 , 
  
 pageToken 
  
  string 
 
 ) 
  
 ( 
 results 
  
 [] 
 * 
  pubsubpb 
 
 . 
  Subscription 
 
 , 
  
 nextPageToken 
  
  string 
 
 , 
  
 err 
  
  error 
 
 ) 
  
 // contains filtered or unexported fields 
 } 
 

SubscriptionIterator manages a stream of *pubsubpb.Subscription.

func (*SubscriptionIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*SubscriptionIterator) PageInfo

  func 
  
 ( 
 it 
  
 * 
  SubscriptionIterator 
 
 ) 
  
 PageInfo 
 () 
  
 * 
  iterator 
 
 . 
  PageInfo 
 
 

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

TopicIterator

  type 
  
 TopicIterator 
  
 struct 
  
 { 
  
 // Response is the raw response for the current page. 
  
 // It must be cast to the RPC response type. 
  
 // Calling Next() or InternalFetch() updates this value. 
  
 Response 
  
 interface 
 {} 
  
 // InternalFetch is for use by the Google Cloud Libraries only. 
  
 // It is not part of the stable interface of this package. 
  
 // 
  
 // InternalFetch returns results from a single call to the underlying RPC. 
  
 // The number of results is no greater than pageSize. 
  
 // If there are no more results, nextPageToken is empty and err is nil. 
  
 InternalFetch 
  
 func 
 ( 
 pageSize 
  
  int 
 
 , 
  
 pageToken 
  
  string 
 
 ) 
  
 ( 
 results 
  
 [] 
 * 
  pubsubpb 
 
 . 
  Topic 
 
 , 
  
 nextPageToken 
  
  string 
 
 , 
  
 err 
  
  error 
 
 ) 
  
 // contains filtered or unexported fields 
 } 
 

TopicIterator manages a stream of *pubsubpb.Topic.

func (*TopicIterator) Next

  func 
  
 ( 
 it 
  
 * 
  TopicIterator 
 
 ) 
  
 Next 
 () 
  
 ( 
 * 
  pubsubpb 
 
 . 
  Topic 
 
 , 
  
  error 
 
 ) 
 

Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.

func (*TopicIterator) PageInfo

  func 
  
 ( 
 it 
  
 * 
  TopicIterator 
 
 ) 
  
 PageInfo 
 () 
  
 * 
  iterator 
 
 . 
  PageInfo 
 
 

PageInfo supports pagination. See the google.golang.org/api/iterator package for details.

Create a Mobile Website
View Site in Mobile | Classic
Share by: