Package com.google.cloud.pubsub.v1 (1.127.3)

A client to Cloud Pub/Sub API

The interfaces provided are listed below, along with usage samples.

TopicAdminClient

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

Sample for TopicAdminClient:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   Topic response = topicAdminClient.createTopic(name);
 }
 

SubscriptionAdminClient

Service Description: 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.

Sample for SubscriptionAdminClient:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
   SubscriptionName name = SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   PushConfig pushConfig = PushConfig.newBuilder().build();
   int ackDeadlineSeconds = 2135351438;
   Subscription response =
       subscriptionAdminClient.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
 }
 

SchemaServiceClient

Service Description: Service for doing schema-related operations.

Sample for SchemaServiceClient:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   Schema schema = Schema.newBuilder().build();
   String schemaId = "schemaId-697673060";
   Schema response = schemaServiceClient.createSchema(parent, schema, schemaId);
 }
 

Classes

AckReplyConsumerImpl

AckReplyConsumerWithResponseImpl

AckRequestData

AckRequestData.Builder

Builder of AckRequestData.

OpenCensusUtil

Utilities for propagating OpenCensus TagContext and SpanContext from publishers to subscribers.

OpenCensusUtil.OpenCensusMessageReceiver

Wrapper class for MessageReceiver that decodes any received trace and tag contexts and puts them in scope.

Publisher

A Cloud Pub/Sub publisher, that is associated with a specific topic at creation.

A Publisher provides built-in capabilities to automatically handle batching of messages, controlling memory utilization, and retrying API calls on transient errors.

With customizable options that control:

  • Message batching: such as number of messages or max batch byte size.
  • Retries: such as the maximum duration of retries for a failing batch of messages.

Publisher will use the credentials set on the channel, which uses application default credentials through GoogleCredentials#getApplicationDefault by default.

Publisher.Builder

A builder of Publishers.

SchemaServiceClient

Service Description: Service for doing schema-related operations.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {
   ProjectName parent = ProjectName.of("[PROJECT]");
   Schema schema = Schema.newBuilder().build();
   String schemaId = "schemaId-697673060";
   Schema response = schemaServiceClient.createSchema(parent, schema, schemaId);
 }
 

Note: close() needs to be called on the SchemaServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
MethodDescriptionMethod Variants

CreateSchema

Creates a schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createSchema(CreateSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • createSchema(ProjectName parent, Schema schema, String schemaId)

  • createSchema(String parent, Schema schema, String schemaId)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createSchemaCallable()

GetSchema

Gets a schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getSchema(GetSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getSchema(SchemaName name)

  • getSchema(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getSchemaCallable()

ListSchemas

Lists schemas in a project.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listSchemas(ListSchemasRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listSchemas(ProjectName parent)

  • listSchemas(String parent)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listSchemasPagedCallable()

  • listSchemasCallable()

ListSchemaRevisions

Lists all schema revisions for the named schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listSchemaRevisions(ListSchemaRevisionsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listSchemaRevisions(SchemaName name)

  • listSchemaRevisions(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listSchemaRevisionsPagedCallable()

  • listSchemaRevisionsCallable()

CommitSchema

Commits a new schema revision to an existing schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • commitSchema(CommitSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • commitSchema(SchemaName name, Schema schema)

  • commitSchema(String name, Schema schema)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • commitSchemaCallable()

RollbackSchema

Creates a new schema revision that is a copy of the provided revision_id.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • rollbackSchema(RollbackSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • rollbackSchema(SchemaName name, String revisionId)

  • rollbackSchema(String name, String revisionId)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • rollbackSchemaCallable()

DeleteSchemaRevision

Deletes a specific schema revision.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteSchemaRevision(DeleteSchemaRevisionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteSchemaRevision(SchemaName name, String revisionId)

  • deleteSchemaRevision(String name, String revisionId)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteSchemaRevisionCallable()

DeleteSchema

Deletes a schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteSchema(DeleteSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteSchema(SchemaName name)

  • deleteSchema(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteSchemaCallable()

ValidateSchema

Validates a schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • validateSchema(ValidateSchemaRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • validateSchema(ProjectName parent, Schema schema)

  • validateSchema(String parent, Schema schema)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • validateSchemaCallable()

ValidateMessage

Validates a message against a schema.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • validateMessage(ValidateMessageRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • validateMessageCallable()

SetIamPolicy

Sets the access control policy on the specified resource. Replacesany existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIEDerrors.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setIamPolicy(SetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setIamPolicyCallable()

GetIamPolicy

Gets the access control policy for a resource. Returns an empty policyif the resource exists and does not have a policy set.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIamPolicy(GetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIamPolicyCallable()

TestIamPermissions

Returns permissions that a caller has on the specified resource. If theresource does not exist, this will return an empty set ofpermissions, not a NOT_FOUND error.

Note: This operation is designed to be used for buildingpermission-aware UIs and command-line tools, not for authorizationchecking. This operation may "fail open" without warning.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • testIamPermissions(TestIamPermissionsRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • testIamPermissionsCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of SchemaServiceSettings to create(). For example:

To customize credentials:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SchemaServiceSettings schemaServiceSettings =
     SchemaServiceSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 SchemaServiceClient schemaServiceClient = SchemaServiceClient.create(schemaServiceSettings);
 

To customize the endpoint:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SchemaServiceSettings schemaServiceSettings =
     SchemaServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
 SchemaServiceClient schemaServiceClient = SchemaServiceClient.create(schemaServiceSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SchemaServiceSettings schemaServiceSettings =
     SchemaServiceSettings.newHttpJsonBuilder().build();
 SchemaServiceClient schemaServiceClient = SchemaServiceClient.create(schemaServiceSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

SchemaServiceClient.ListSchemaRevisionsFixedSizeCollection

SchemaServiceClient.ListSchemaRevisionsPage

SchemaServiceClient.ListSchemaRevisionsPagedResponse

SchemaServiceClient.ListSchemasFixedSizeCollection

SchemaServiceClient.ListSchemasPage

SchemaServiceClient.ListSchemasPagedResponse

SchemaServiceSettings

Settings class to configure an instance of SchemaServiceClient.

The default instance has everything set to sensible defaults:

  • The default service address (pubsub.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of createSchema to 30 seconds:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SchemaServiceSettings.Builder schemaServiceSettingsBuilder = SchemaServiceSettings.newBuilder();
 schemaServiceSettingsBuilder
     .createSchemaSettings()
     .setRetrySettings(
         schemaServiceSettingsBuilder
             .createSchemaSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 SchemaServiceSettings schemaServiceSettings = schemaServiceSettingsBuilder.build();
 

SchemaServiceSettings.Builder

Builder for SchemaServiceSettings.

Subscriber

A Cloud Pub/Sub subscriber that is associated with a specific subscription at creation.

A Subscriber allows you to provide an implementation of a receiver to which messages are going to be delivered as soon as they are received by the subscriber. The delivered messages then can be acked or nacked at will as they get processed by the receiver. Nacking a messages implies a later redelivery of such message.

The subscriber handles the ack management, by automatically extending the ack deadline while the message is being processed, to then issue the ack or nack of such message when the processing is done (see Builder#setMaxAckExtensionPeriod(Duration)). Note: message redelivery is still possible.

It also provides customizable options that control:

  • Ack deadline extension: such as the amount of time ahead to trigger the extension of message acknowledgement expiration.
  • Flow control: such as the maximum outstanding messages or maximum outstanding bytes to keep in memory before the receiver either ack or nack them.

Subscriber will use the credentials set on the channel, which uses application default credentials through GoogleCredentials#getApplicationDefault by default.

Subscriber is implemented using Guava's Service and provides the same methods. See Guava documentation for more details.

Subscriber.Builder

Builder of Subscribers.

SubscriptionAdminClient

Service Description: 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.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
   SubscriptionName name = SubscriptionName.of("[PROJECT]", "[SUBSCRIPTION]");
   TopicName topic = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   PushConfig pushConfig = PushConfig.newBuilder().build();
   int ackDeadlineSeconds = 2135351438;
   Subscription response =
       subscriptionAdminClient.createSubscription(name, topic, pushConfig, ackDeadlineSeconds);
 }
 

Note: close() needs to be called on the SubscriptionAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
MethodDescriptionMethod Variants

CreateSubscription

Creates a subscription to a given topic. See the resource name rules. 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. The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createSubscription(Subscription request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • createSubscription(SubscriptionName name, TopicName topic, PushConfig pushConfig, int ackDeadlineSeconds)

  • createSubscription(SubscriptionName name, String topic, PushConfig pushConfig, int ackDeadlineSeconds)

  • createSubscription(String name, TopicName topic, PushConfig pushConfig, int ackDeadlineSeconds)

  • createSubscription(String name, String topic, PushConfig pushConfig, int ackDeadlineSeconds)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createSubscriptionCallable()

GetSubscription

Gets the configuration details of a subscription.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getSubscription(GetSubscriptionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getSubscription(SubscriptionName subscription)

  • getSubscription(String subscription)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getSubscriptionCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateSubscription(UpdateSubscriptionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • updateSubscription(Subscription subscription, FieldMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateSubscriptionCallable()

ListSubscriptions

Lists matching subscriptions.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listSubscriptions(ListSubscriptionsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listSubscriptions(ProjectName project)

  • listSubscriptions(String project)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listSubscriptionsPagedCallable()

  • listSubscriptionsCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteSubscription(DeleteSubscriptionRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteSubscription(SubscriptionName subscription)

  • deleteSubscription(String subscription)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteSubscriptionCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • modifyAckDeadline(ModifyAckDeadlineRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • modifyAckDeadline(SubscriptionName subscription, List<String> ackIds, int ackDeadlineSeconds)

  • modifyAckDeadline(String subscription, List<String> ackIds, int ackDeadlineSeconds)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • modifyAckDeadlineCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • acknowledge(AcknowledgeRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • acknowledge(SubscriptionName subscription, List<String> ackIds)

  • acknowledge(String subscription, List<String> ackIds)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • acknowledgeCallable()

Pull

Pulls messages from the server.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • pull(PullRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • pull(SubscriptionName subscription, int maxMessages)

  • pull(String subscription, int maxMessages)

  • pull(SubscriptionName subscription, boolean returnImmediately, int maxMessages)

  • pull(String subscription, boolean returnImmediately, int maxMessages)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • pullCallable()

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.

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • streamingPullCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • modifyPushConfig(ModifyPushConfigRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • modifyPushConfig(SubscriptionName subscription, PushConfig pushConfig)

  • modifyPushConfig(String subscription, PushConfig pushConfig)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • modifyPushConfigCallable()

GetSnapshot

Gets the configuration details of a snapshot. Snapshots are used in Seek 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getSnapshot(GetSnapshotRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getSnapshot(SnapshotName snapshot)

  • getSnapshot(String snapshot)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getSnapshotCallable()

ListSnapshots

Lists the existing snapshots. Snapshots are used in Seek 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listSnapshots(ListSnapshotsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listSnapshots(ProjectName project)

  • listSnapshots(String project)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listSnapshotsPagedCallable()

  • listSnapshotsCallable()

CreateSnapshot

Creates a snapshot from the requested subscription. Snapshots are used in Seek 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. The generated name is populated in the returned Snapshot object. Note that for REST API requests, you must specify a name in the request.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createSnapshot(CreateSnapshotRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • createSnapshot(SnapshotName name, SubscriptionName subscription)

  • createSnapshot(SnapshotName name, String subscription)

  • createSnapshot(String name, SubscriptionName subscription)

  • createSnapshot(String name, String subscription)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createSnapshotCallable()

UpdateSnapshot

Updates an existing snapshot by updating the fields specified in the update mask. Snapshots are used in Seek 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateSnapshot(UpdateSnapshotRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • updateSnapshot(Snapshot snapshot, FieldMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateSnapshotCallable()

DeleteSnapshot

Removes an existing snapshot. Snapshots are used in Seek 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteSnapshot(DeleteSnapshotRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteSnapshot(SnapshotName snapshot)

  • deleteSnapshot(String snapshot)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteSnapshotCallable()

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 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • seek(SeekRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • seekCallable()

SetIamPolicy

Sets the access control policy on the specified resource. Replacesany existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIEDerrors.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setIamPolicy(SetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setIamPolicyCallable()

GetIamPolicy

Gets the access control policy for a resource. Returns an empty policyif the resource exists and does not have a policy set.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIamPolicy(GetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIamPolicyCallable()

TestIamPermissions

Returns permissions that a caller has on the specified resource. If theresource does not exist, this will return an empty set ofpermissions, not a NOT_FOUND error.

Note: This operation is designed to be used for buildingpermission-aware UIs and command-line tools, not for authorizationchecking. This operation may "fail open" without warning.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • testIamPermissions(TestIamPermissionsRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • testIamPermissionsCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of SubscriptionAdminSettings to create(). For example:

To customize credentials:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SubscriptionAdminSettings subscriptionAdminSettings =
     SubscriptionAdminSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 SubscriptionAdminClient subscriptionAdminClient =
     SubscriptionAdminClient.create(subscriptionAdminSettings);
 

To customize the endpoint:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SubscriptionAdminSettings subscriptionAdminSettings =
     SubscriptionAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
 SubscriptionAdminClient subscriptionAdminClient =
     SubscriptionAdminClient.create(subscriptionAdminSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SubscriptionAdminSettings subscriptionAdminSettings =
     SubscriptionAdminSettings.newHttpJsonBuilder().build();
 SubscriptionAdminClient subscriptionAdminClient =
     SubscriptionAdminClient.create(subscriptionAdminSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

SubscriptionAdminClient.ListSnapshotsFixedSizeCollection

SubscriptionAdminClient.ListSnapshotsPage

SubscriptionAdminClient.ListSnapshotsPagedResponse

SubscriptionAdminClient.ListSubscriptionsFixedSizeCollection

SubscriptionAdminClient.ListSubscriptionsPage

SubscriptionAdminClient.ListSubscriptionsPagedResponse

SubscriptionAdminSettings

Settings class to configure an instance of SubscriptionAdminClient.

The default instance has everything set to sensible defaults:

  • The default service address (pubsub.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of createSubscription to 30 seconds:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 SubscriptionAdminSettings.Builder subscriptionAdminSettingsBuilder =
     SubscriptionAdminSettings.newBuilder();
 subscriptionAdminSettingsBuilder
     .createSubscriptionSettings()
     .setRetrySettings(
         subscriptionAdminSettingsBuilder
             .createSubscriptionSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 SubscriptionAdminSettings subscriptionAdminSettings = subscriptionAdminSettingsBuilder.build();
 

SubscriptionAdminSettings.Builder

Builder for SubscriptionAdminSettings.

TopicAdminClient

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

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) {
   TopicName name = TopicName.ofProjectTopicName("[PROJECT]", "[TOPIC]");
   Topic response = topicAdminClient.createTopic(name);
 }
 

Note: close() needs to be called on the TopicAdminClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().

Methods
MethodDescriptionMethod Variants

CreateTopic

Creates the given topic with the given name. See the resource name rules.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • createTopic(Topic request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • createTopic(TopicName name)

  • createTopic(String name)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • createTopicCallable()

UpdateTopic

Updates an existing topic by updating the fields specified in the update mask. Note that certain properties of a topic are not modifiable.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • updateTopic(UpdateTopicRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • updateTopic(Topic topic, FieldMask updateMask)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • updateTopicCallable()

Publish

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

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • publish(PublishRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • publish(TopicName topic, List<PubsubMessage> messages)

  • publish(String topic, List<PubsubMessage> messages)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • publishCallable()

GetTopic

Gets the configuration of a topic.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getTopic(GetTopicRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • getTopic(TopicName topic)

  • getTopic(String topic)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getTopicCallable()

ListTopics

Lists matching topics.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listTopics(ListTopicsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listTopics(ProjectName project)

  • listTopics(String project)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listTopicsPagedCallable()

  • listTopicsCallable()

ListTopicSubscriptions

Lists the names of the attached subscriptions on this topic.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listTopicSubscriptions(ListTopicSubscriptionsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listTopicSubscriptions(TopicName topic)

  • listTopicSubscriptions(String topic)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listTopicSubscriptionsPagedCallable()

  • listTopicSubscriptionsCallable()

ListTopicSnapshots

Lists the names of the snapshots on this topic. Snapshots are used in Seek 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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • listTopicSnapshots(ListTopicSnapshotsRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • listTopicSnapshots(TopicName topic)

  • listTopicSnapshots(String topic)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • listTopicSnapshotsPagedCallable()

  • listTopicSnapshotsCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • deleteTopic(DeleteTopicRequest request)

"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.

  • deleteTopic(TopicName topic)

  • deleteTopic(String topic)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • deleteTopicCallable()

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.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • detachSubscription(DetachSubscriptionRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • detachSubscriptionCallable()

SetIamPolicy

Sets the access control policy on the specified resource. Replacesany existing policy.

Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIEDerrors.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • setIamPolicy(SetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • setIamPolicyCallable()

GetIamPolicy

Gets the access control policy for a resource. Returns an empty policyif the resource exists and does not have a policy set.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • getIamPolicy(GetIamPolicyRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • getIamPolicyCallable()

TestIamPermissions

Returns permissions that a caller has on the specified resource. If theresource does not exist, this will return an empty set ofpermissions, not a NOT_FOUND error.

Note: This operation is designed to be used for buildingpermission-aware UIs and command-line tools, not for authorizationchecking. This operation may "fail open" without warning.

Request object method variants only take one parameter, a request object, which must be constructed before the call.

  • testIamPermissions(TestIamPermissionsRequest request)

Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.

  • testIamPermissionsCallable()

See the individual methods for example code.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.

This class can be customized by passing in a custom instance of TopicAdminSettings to create(). For example:

To customize credentials:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TopicAdminSettings topicAdminSettings =
     TopicAdminSettings.newBuilder()
         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
         .build();
 TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
 

To customize the endpoint:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TopicAdminSettings topicAdminSettings =
     TopicAdminSettings.newBuilder().setEndpoint(myEndpoint).build();
 TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
 

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TopicAdminSettings topicAdminSettings = TopicAdminSettings.newHttpJsonBuilder().build();
 TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings);
 

Please refer to the GitHub repository's samples for more quickstart code snippets.

TopicAdminClient.ListTopicSnapshotsFixedSizeCollection

TopicAdminClient.ListTopicSnapshotsPage

TopicAdminClient.ListTopicSnapshotsPagedResponse

TopicAdminClient.ListTopicSubscriptionsFixedSizeCollection

TopicAdminClient.ListTopicSubscriptionsPage

TopicAdminClient.ListTopicSubscriptionsPagedResponse

TopicAdminClient.ListTopicsFixedSizeCollection

TopicAdminClient.ListTopicsPage

TopicAdminClient.ListTopicsPagedResponse

TopicAdminSettings

Settings class to configure an instance of TopicAdminClient.

The default instance has everything set to sensible defaults:

  • The default service address (pubsub.googleapis.com) and default port (443) are used.
  • Credentials are acquired automatically through Application Default Credentials.
  • Retries are configured for idempotent methods but not for non-idempotent methods.

The builder of this class is recursive, so contained classes are themselves builders. When build() is called, the tree of builders is called to create the complete settings object.

For example, to set the total timeout of createTopic to 30 seconds:


 // 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://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
 TopicAdminSettings.Builder topicAdminSettingsBuilder = TopicAdminSettings.newBuilder();
 topicAdminSettingsBuilder
     .createTopicSettings()
     .setRetrySettings(
         topicAdminSettingsBuilder
             .createTopicSettings()
             .getRetrySettings()
             .toBuilder()
             .setTotalTimeout(Duration.ofSeconds(30))
             .build());
 TopicAdminSettings topicAdminSettings = topicAdminSettingsBuilder.build();
 

TopicAdminSettings.Builder

Builder for TopicAdminSettings.

Interfaces

AckReplyConsumer

Accepts a reply, sending it to the service.

AckReplyConsumerWithResponse

Acknowledging a message in Pub/Sub means that you are done with it, and it will not be delivered to this subscription again. You should avoid acknowledging messages until you have finished processing them, so that in the event of a failure, you receive the message again.

If exactly-once delivery is enabled on the subscription, the future returned by the ack/nack methods track the state of acknowledgement operation by the server. If the future completes successfully, the message is guaranteed NOT to be re-delivered. Otherwise, the future will contain an exception with more details about the failure and the message may be re-delivered.

If exactly-once delivery is NOT enabled on the subscription, the future returns immediately with an AckResponse.SUCCESS. Because re-deliveries are possible, you should ensure that your processing code is idempotent, as you may receive any given message more than once.

MessageReceiver

This interface can be implemented by users of Subscriber to receive messages.

MessageReceiverWithAckResponse

PublisherInterface

An interface for a Cloud Pub/Sub publisher.

SubscriberInterface

The core interface for a Cloud Pub/Sub subscriber, consisting only of ApiService methods.

Enums

AckResponse