Package pubsub is an auto-generated package for the Cloud Pub/Sub API.
Provides reliable, many-to-many, asynchronous messaging between applications.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/pubsub/v2/apiv1@latest ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := pubsub.NewSchemaClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req := &pubsubpb.CommitSchemaRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CommitSchemaRequest. } resp, err := c.CommitSchema(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewSchemaClient 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.
Functions
func DefaultAuthScopes
func DefaultAuthScopes() []stringDefaultAuthScopes reports the default set of authentication scopes to use with this package.
SchemaCallOptions
type SchemaCallOptions struct {
CreateSchema []gax.CallOption
GetSchema []gax.CallOption
ListSchemas []gax.CallOption
ListSchemaRevisions []gax.CallOption
CommitSchema []gax.CallOption
RollbackSchema []gax.CallOption
DeleteSchemaRevision []gax.CallOption
DeleteSchema []gax.CallOption
ValidateSchema []gax.CallOption
ValidateMessage []gax.CallOption
GetIamPolicy []gax.CallOption
SetIamPolicy []gax.CallOption
TestIamPermissions []gax.CallOption
}SchemaCallOptions contains the retry settings for each method of SchemaClient.
SchemaClient
type SchemaClient struct {
// The call options for this service.
CallOptions *SchemaCallOptions
// contains filtered or unexported fields
}SchemaClient 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.
Service for doing schema-related operations.
func NewSchemaClient
func NewSchemaClient(ctx context.Context, opts ...option.ClientOption) (*SchemaClient, error)NewSchemaClient creates a new schema service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Service for doing schema-related operations.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewSchemaRESTClient
func NewSchemaRESTClient(ctx context.Context, opts ...option.ClientOption) (*SchemaClient, error)NewSchemaRESTClient creates a new schema service rest client.
Service for doing schema-related operations.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*SchemaClient) Close
func (c *SchemaClient) Close() errorClose closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*SchemaClient) CommitSchema
func (c *SchemaClient) CommitSchema(ctx context.Context, req *pubsubpb.CommitSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error)CommitSchema commits a new schema revision to an existing schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.CommitSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CommitSchemaRequest.
}
resp, err := c.CommitSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) Connection (deprecated)
func (c *SchemaClient) Connection() *grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*SchemaClient) CreateSchema
func (c *SchemaClient) CreateSchema(ctx context.Context, req *pubsubpb.CreateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error)CreateSchema creates a schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.CreateSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CreateSchemaRequest.
}
resp, err := c.CreateSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) DeleteSchema
func (c *SchemaClient) DeleteSchema(ctx context.Context, req *pubsubpb.DeleteSchemaRequest, opts ...gax.CallOption) errorDeleteSchema deletes a schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DeleteSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSchemaRequest.
}
err = c.DeleteSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SchemaClient) DeleteSchemaRevision
func (c *SchemaClient) DeleteSchemaRevision(ctx context.Context, req *pubsubpb.DeleteSchemaRevisionRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error)DeleteSchemaRevision deletes a specific schema revision.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DeleteSchemaRevisionRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSchemaRevisionRequest.
}
resp, err := c.DeleteSchemaRevision(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) GetIamPolicy
func (c *SchemaClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)GetIamPolicy gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.GetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
}
resp, err := c.GetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) GetSchema
func (c *SchemaClient) GetSchema(ctx context.Context, req *pubsubpb.GetSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error)GetSchema gets a schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.GetSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetSchemaRequest.
}
resp, err := c.GetSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) ListSchemaRevisions
func (c *SchemaClient) ListSchemaRevisions(ctx context.Context, req *pubsubpb.ListSchemaRevisionsRequest, opts ...gax.CallOption) *SchemaIteratorListSchemaRevisions lists all schema revisions for the named schema.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSchemaRevisionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemaRevisionsRequest.
}
it := c.ListSchemaRevisions(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListSchemaRevisionsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSchemaRevisionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemaRevisionsRequest.
}
for resp, err := range c.ListSchemaRevisions(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*SchemaClient) ListSchemas
func (c *SchemaClient) ListSchemas(ctx context.Context, req *pubsubpb.ListSchemasRequest, opts ...gax.CallOption) *SchemaIteratorListSchemas lists schemas in a project.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSchemasRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemasRequest.
}
it := c.ListSchemas(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListSchemasResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSchemasRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSchemasRequest.
}
for resp, err := range c.ListSchemas(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*SchemaClient) RollbackSchema
func (c *SchemaClient) RollbackSchema(ctx context.Context, req *pubsubpb.RollbackSchemaRequest, opts ...gax.CallOption) (*pubsubpb.Schema, error)RollbackSchema creates a new schema revision that is a copy of the provided revision_id.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.RollbackSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#RollbackSchemaRequest.
}
resp, err := c.RollbackSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) SetIamPolicy
func (c *SchemaClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.SetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
}
resp, err := c.SetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) TestIamPermissions
func (c *SchemaClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)TestIamPermissions returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.
Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may “fail open” without warning.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.TestIamPermissionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
}
resp, err := c.TestIamPermissions(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) ValidateMessage
func (c *SchemaClient) ValidateMessage(ctx context.Context, req *pubsubpb.ValidateMessageRequest, opts ...gax.CallOption) (*pubsubpb.ValidateMessageResponse, error)ValidateMessage validates a message against a schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ValidateMessageRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ValidateMessageRequest.
}
resp, err := c.ValidateMessage(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SchemaClient) ValidateSchema
func (c *SchemaClient) ValidateSchema(ctx context.Context, req *pubsubpb.ValidateSchemaRequest, opts ...gax.CallOption) (*pubsubpb.ValidateSchemaResponse, error)ValidateSchema validates a schema.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSchemaClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ValidateSchemaRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ValidateSchemaRequest.
}
resp, err := c.ValidateSchema(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
SchemaIterator
type SchemaIterator 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.Schema, nextPageToken string, err error)
// contains filtered or unexported fields
}SchemaIterator manages a stream of *pubsubpb.Schema.
func (*SchemaIterator) All
func (it *SchemaIterator) All() iter.Seq2[*pubsubpb.Schema, error]All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*SchemaIterator) Next
func (it *SchemaIterator) Next() (*pubsubpb.Schema, 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 (*SchemaIterator) PageInfo
func (it *SchemaIterator) PageInfo() *iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
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) All
func (it *SnapshotIterator) All() iter.Seq2[*pubsubpb.Snapshot, error]All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*SnapshotIterator) Next
func (it *SnapshotIterator) Next() (*pubsubpb.Snapshot, 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 (*SnapshotIterator) PageInfo
func (it *SnapshotIterator) PageInfo() *iterator.PageInfoPageInfo 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) All
func (it *StringIterator) All() iter.Seq2[string, error]All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
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.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
SubscriptionAdminCallOptions
type SubscriptionAdminCallOptions 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
GetIamPolicy []gax.CallOption
SetIamPolicy []gax.CallOption
TestIamPermissions []gax.CallOption
}SubscriptionAdminCallOptions contains the retry settings for each method of SubscriptionAdminClient.
SubscriptionAdminClient
type SubscriptionAdminClient struct {
// The call options for this service.
CallOptions *SubscriptionAdminCallOptions
// contains filtered or unexported fields
}SubscriptionAdminClient 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.
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.
func NewSubscriptionAdminClient
func NewSubscriptionAdminClient(ctx context.Context, opts ...option.ClientOption) (*SubscriptionAdminClient, error)NewSubscriptionAdminClient creates a new subscription admin client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
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/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewSubscriptionAdminRESTClient
func NewSubscriptionAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*SubscriptionAdminClient, error)NewSubscriptionAdminRESTClient creates a new subscription admin rest 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/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*SubscriptionAdminClient) Acknowledge
func (c *SubscriptionAdminClient) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest, opts ...gax.CallOption) errorAcknowledge 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.AcknowledgeRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#AcknowledgeRequest.
}
err = c.Acknowledge(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SubscriptionAdminClient) Close
func (c *SubscriptionAdminClient) Close() errorClose closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*SubscriptionAdminClient) Connection (deprecated)
func (c *SubscriptionAdminClient) Connection() *grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*SubscriptionAdminClient) CreateSnapshot
func (c *SubscriptionAdminClient) CreateSnapshot(ctx context.Context, req *pubsubpb.CreateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error)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/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.CreateSnapshotRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#CreateSnapshotRequest.
}
resp, err := c.CreateSnapshot(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) CreateSubscription
func (c *SubscriptionAdminClient) CreateSubscription(ctx context.Context, req *pubsubpb.Subscription, opts ...gax.CallOption) (*pubsubpb.Subscription, error)CreateSubscription creates a subscription to a given topic. See the [resource name rules] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#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/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.Subscription{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#Subscription.
}
resp, err := c.CreateSubscription(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) DeleteSnapshot
func (c *SubscriptionAdminClient) DeleteSnapshot(ctx context.Context, req *pubsubpb.DeleteSnapshotRequest, opts ...gax.CallOption) errorDeleteSnapshot 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DeleteSnapshotRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSnapshotRequest.
}
err = c.DeleteSnapshot(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SubscriptionAdminClient) DeleteSubscription
func (c *SubscriptionAdminClient) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest, opts ...gax.CallOption) errorDeleteSubscription 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DeleteSubscriptionRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteSubscriptionRequest.
}
err = c.DeleteSubscription(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SubscriptionAdminClient) GetIamPolicy
func (c *SubscriptionAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)GetIamPolicy gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.GetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
}
resp, err := c.GetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) GetSnapshot
func (c *SubscriptionAdminClient) GetSnapshot(ctx context.Context, req *pubsubpb.GetSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error)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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.GetSnapshotRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetSnapshotRequest.
}
resp, err := c.GetSnapshot(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) GetSubscription
func (c *SubscriptionAdminClient) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error)GetSubscription gets the configuration details of a subscription.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.GetSubscriptionRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetSubscriptionRequest.
}
resp, err := c.GetSubscription(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) ListSnapshots
func (c *SubscriptionAdminClient) ListSnapshots(ctx context.Context, req *pubsubpb.ListSnapshotsRequest, opts ...gax.CallOption) *SnapshotIteratorListSnapshots 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.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSnapshotsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSnapshotsRequest.
}
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
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListSnapshotsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSnapshotsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSnapshotsRequest.
}
for resp, err := range c.ListSnapshots(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*SubscriptionAdminClient) ListSubscriptions
func (c *SubscriptionAdminClient) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest, opts ...gax.CallOption) *SubscriptionIteratorListSubscriptions lists matching subscriptions.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSubscriptionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSubscriptionsRequest.
}
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
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListSubscriptionsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListSubscriptionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListSubscriptionsRequest.
}
for resp, err := range c.ListSubscriptions(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*SubscriptionAdminClient) ModifyAckDeadline
func (c *SubscriptionAdminClient) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest, opts ...gax.CallOption) errorModifyAckDeadline 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ModifyAckDeadlineRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ModifyAckDeadlineRequest.
}
err = c.ModifyAckDeadline(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SubscriptionAdminClient) ModifyPushConfig
func (c *SubscriptionAdminClient) ModifyPushConfig(ctx context.Context, req *pubsubpb.ModifyPushConfigRequest, opts ...gax.CallOption) errorModifyPushConfig 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ModifyPushConfigRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ModifyPushConfigRequest.
}
err = c.ModifyPushConfig(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*SubscriptionAdminClient) Pull
func (c *SubscriptionAdminClient) Pull(ctx context.Context, req *pubsubpb.PullRequest, opts ...gax.CallOption) (*pubsubpb.PullResponse, error)Pull pulls messages from the server.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.PullRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#PullRequest.
}
resp, err := c.Pull(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) Seek
func (c *SubscriptionAdminClient) Seek(ctx context.Context, req *pubsubpb.SeekRequest, opts ...gax.CallOption) (*pubsubpb.SeekResponse, error)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] (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. 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.SeekRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#SeekRequest.
}
resp, err := c.Seek(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) SetGoogleClientInfo
func (sc *SubscriptionAdminClient) 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 (*SubscriptionAdminClient) SetIamPolicy
func (c *SubscriptionAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.SetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
}
resp, err := c.SetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) StreamingPull
func (c *SubscriptionAdminClient) StreamingPull(ctx context.Context, opts ...gax.CallOption) (pubsubpb.Subscriber_StreamingPullClient, error)StreamingPull establishes a stream with the server, which sends messages down to the client. The client streams acknowledgments 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.
This method is not supported for the REST transport.
Example
package main
import (
"context"
"io"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
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 (*SubscriptionAdminClient) TestIamPermissions
func (c *SubscriptionAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)TestIamPermissions returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.
Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may “fail open” without warning.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.TestIamPermissionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
}
resp, err := c.TestIamPermissions(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) UpdateSnapshot
func (c *SubscriptionAdminClient) UpdateSnapshot(ctx context.Context, req *pubsubpb.UpdateSnapshotRequest, opts ...gax.CallOption) (*pubsubpb.Snapshot, error)UpdateSnapshot updates an existing snapshot by updating the fields specified in the update mask. 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.UpdateSnapshotRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#UpdateSnapshotRequest.
}
resp, err := c.UpdateSnapshot(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*SubscriptionAdminClient) UpdateSubscription
func (c *SubscriptionAdminClient) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.Subscription, error)UpdateSubscription updates an existing subscription by updating the fields specified in the update mask. 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewSubscriptionAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.UpdateSubscriptionRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#UpdateSubscriptionRequest.
}
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) All
func (it *SubscriptionIterator) All() iter.Seq2[*pubsubpb.Subscription, error]All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*SubscriptionIterator) Next
func (it *SubscriptionIterator) Next() (*pubsubpb.Subscription, 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 (*SubscriptionIterator) PageInfo
func (it *SubscriptionIterator) PageInfo() *iterator.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
TopicAdminCallOptions
type TopicAdminCallOptions 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
GetIamPolicy []gax.CallOption
SetIamPolicy []gax.CallOption
TestIamPermissions []gax.CallOption
}TopicAdminCallOptions contains the retry settings for each method of TopicAdminClient.
TopicAdminClient
type TopicAdminClient struct {
// The call options for this service.
CallOptions *TopicAdminCallOptions
// contains filtered or unexported fields
}TopicAdminClient 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.
The service that an application uses to manipulate topics, and to send messages to a topic.
func NewTopicAdminClient
func NewTopicAdminClient(ctx context.Context, opts ...option.ClientOption) (*TopicAdminClient, error)NewTopicAdminClient creates a new topic admin client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
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/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewTopicAdminRESTClient
func NewTopicAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*TopicAdminClient, error)NewTopicAdminRESTClient creates a new topic admin rest 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/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*TopicAdminClient) Close
func (c *TopicAdminClient) Close() errorClose closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*TopicAdminClient) Connection (deprecated)
func (c *TopicAdminClient) Connection() *grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*TopicAdminClient) CreateTopic
func (c *TopicAdminClient) CreateTopic(ctx context.Context, req *pubsubpb.Topic, opts ...gax.CallOption) (*pubsubpb.Topic, error)CreateTopic creates the given topic with the given name. See the [resource name rules] (https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names (at https://cloud.google.com/pubsub/docs/pubsub-basics#resource_names)).
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.Topic{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#Topic.
}
resp, err := c.CreateTopic(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) DeleteTopic
func (c *TopicAdminClient) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest, opts ...gax.CallOption) errorDeleteTopic 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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DeleteTopicRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DeleteTopicRequest.
}
err = c.DeleteTopic(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*TopicAdminClient) DetachSubscription
func (c *TopicAdminClient) DetachSubscription(ctx context.Context, req *pubsubpb.DetachSubscriptionRequest, opts ...gax.CallOption) (*pubsubpb.DetachSubscriptionResponse, error)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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.DetachSubscriptionRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#DetachSubscriptionRequest.
}
resp, err := c.DetachSubscription(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) GetIamPolicy
func (c *TopicAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)GetIamPolicy gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.GetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
}
resp, err := c.GetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) GetTopic
func (c *TopicAdminClient) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error)GetTopic gets the configuration of a topic.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.GetTopicRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#GetTopicRequest.
}
resp, err := c.GetTopic(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) ListTopicSnapshots
func (c *TopicAdminClient) ListTopicSnapshots(ctx context.Context, req *pubsubpb.ListTopicSnapshotsRequest, opts ...gax.CallOption) *StringIteratorListTopicSnapshots 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.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicSnapshotsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSnapshotsRequest.
}
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
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListTopicSnapshotsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicSnapshotsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSnapshotsRequest.
}
for resp, err := range c.ListTopicSnapshots(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*TopicAdminClient) ListTopicSubscriptions
func (c *TopicAdminClient) ListTopicSubscriptions(ctx context.Context, req *pubsubpb.ListTopicSubscriptionsRequest, opts ...gax.CallOption) *StringIteratorListTopicSubscriptions lists the names of the attached subscriptions on this topic.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicSubscriptionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSubscriptionsRequest.
}
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
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListTopicSubscriptionsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicSubscriptionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicSubscriptionsRequest.
}
for resp, err := range c.ListTopicSubscriptions(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*TopicAdminClient) ListTopics
func (c *TopicAdminClient) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest, opts ...gax.CallOption) *TopicIteratorListTopics lists matching topics.
Examples
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicsRequest.
}
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
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*pubsubpb.ListTopicsResponse)
}
}
all
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.ListTopicsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#ListTopicsRequest.
}
for resp, err := range c.ListTopics(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*TopicAdminClient) Publish
func (c *TopicAdminClient) Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error)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/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.PublishRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#PublishRequest.
}
resp, err := c.Publish(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) SetGoogleClientInfo
func (tc *TopicAdminClient) 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 (*TopicAdminClient) SetIamPolicy
func (c *TopicAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)SetIamPolicy sets the access control policy on the specified resource. Replaces any existing policy.
Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.SetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
}
resp, err := c.SetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) TestIamPermissions
func (c *TopicAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)TestIamPermissions returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.
Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may “fail open” without warning.
Example
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.TestIamPermissionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
}
resp, err := c.TestIamPermissions(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*TopicAdminClient) UpdateTopic
func (c *TopicAdminClient) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest, opts ...gax.CallOption) (*pubsubpb.Topic, error)UpdateTopic updates an existing topic by updating the fields specified in the update mask. Note that certain properties of a topic are not modifiable.
Example
package main
import (
"context"
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
pubsubpb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := pubsub.NewTopicAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &pubsubpb.UpdateTopicRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/pubsub/v2/apiv1/pubsubpb#UpdateTopicRequest.
}
resp, err := c.UpdateTopic(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
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) All
func (it *TopicIterator) All() iter.Seq2[*pubsubpb.Topic, error]All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
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.PageInfoPageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.