A client to Pub/Sub Lite API
The interfaces provided are listed below, along with usage samples.
AdminServiceClient
Service Description: The service that a client application uses to manage topics and subscriptions, such creating, listing, and deleting topics and subscriptions.
Sample for AdminServiceClient:
// 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 (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Topic topic = Topic.newBuilder().build();
String topicId = "topicId-1139259734";
Topic response = adminServiceClient.createTopic(parent, topic, topicId);
}
CursorServiceClient
Service Description: The service that a subscriber client application uses to manage committed cursors while receiving messsages. A cursor represents a subscriber's progress within a topic partition for a given subscription.
Sample for CursorServiceClient:
// 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 (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
CommitCursorRequest request =
CommitCursorRequest.newBuilder()
.setSubscription("subscription341203229")
.setPartition(-1799810326)
.setCursor(Cursor.newBuilder().build())
.build();
CommitCursorResponse response = cursorServiceClient.commitCursor(request);
}
PublisherServiceClient
Service Description: The service that a publisher client application uses to publish messages
to topics. Published messages are retained by the service for the duration of the retention
period configured for the respective topic, and are delivered to subscriber clients upon request
(via the SubscriberService
).
Sample for PublisherServiceClient:
// 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 (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
BidiStream<PublishRequest, PublishResponse> bidiStream =
publisherServiceClient.publishCallable().call();
PublishRequest request = PublishRequest.newBuilder().build();
bidiStream.send(request);
for (PublishResponse response : bidiStream) {
// Do something when a response is received.
}
}
SubscriberServiceClient
Service Description: The service that a subscriber client application uses to receive messages from subscriptions.
Sample for SubscriberServiceClient:
// 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 (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
subscriberServiceClient.subscribeCallable().call();
SubscribeRequest request = SubscribeRequest.newBuilder().build();
bidiStream.send(request);
for (SubscribeResponse response : bidiStream) {
// Do something when a response is received.
}
}
PartitionAssignmentServiceClient
Service Description: The service that a subscriber client application uses to determine which partitions it should connect to.
Sample for PartitionAssignmentServiceClient:
// 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 (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
PartitionAssignmentServiceClient.create()) {
BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
partitionAssignmentServiceClient.assignPartitionsCallable().call();
PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
bidiStream.send(request);
for (PartitionAssignment response : bidiStream) {
// Do something when a response is received.
}
}
TopicStatsServiceClient
Service Description: This service allows users to get stats about messages in their topic.
Sample for TopicStatsServiceClient:
// 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 (TopicStatsServiceClient topicStatsServiceClient = TopicStatsServiceClient.create()) {
ComputeMessageStatsRequest request =
ComputeMessageStatsRequest.newBuilder()
.setTopic(TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]").toString())
.setPartition(-1799810326)
.setStartCursor(Cursor.newBuilder().build())
.setEndCursor(Cursor.newBuilder().build())
.build();
ComputeMessageStatsResponse response = topicStatsServiceClient.computeMessageStats(request);
}
Classes
AdminServiceClient
Service Description: The service that a client application uses to manage topics and subscriptions, such creating, listing, and deleting topics and subscriptions.
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 (AdminServiceClient adminServiceClient = AdminServiceClient.create()) {
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
Topic topic = Topic.newBuilder().build();
String topicId = "topicId-1139259734";
Topic response = adminServiceClient.createTopic(parent, topic, topicId);
}
Note: close() needs to be called on the AdminServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
CreateTopic | Creates a new topic. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetTopic | Returns the topic configuration. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetTopicPartitions | Returns the partition information for the requested topic. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListTopics | Returns the list of topics for the given project. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateTopic | Updates properties of the specified topic. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
DeleteTopic | Deletes the specified topic. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListTopicSubscriptions | Lists the subscriptions attached to the specified topic. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
CreateSubscription | Creates a new subscription. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetSubscription | Returns the subscription configuration. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListSubscriptions | Returns the list of subscriptions for the given project. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateSubscription | Updates properties of the specified subscription. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
DeleteSubscription | Deletes the specified subscription. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
SeekSubscription | Performs an out-of-band seek for a subscription to a specified target, which may be timestamps or named positions within the message backlog. Seek translates these targets to cursors for each partition and orchestrates subscribers to start consuming messages from these seek cursors. If an operation is returned, the seek has been registered and subscribers will eventually receive messages from the seek cursors (i.e. eventual consistency), as long as they are using a minimum supported client library version and not a system that tracks cursors independently of Pub/Sub Lite (e.g. Apache Beam, Dataflow, Spark). The seek operation will fail for unsupported clients. If clients would like to know when subscribers react to the seek (or not), they can poll the operation. The seek operation will succeed and complete once subscribers are ready to receive messages from the seek cursors for all partitions of the topic. This means that the seek operation will not complete until all subscribers come online. If the previous seek operation has not yet completed, it will be aborted and the new invocation of seek will supersede it. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
CreateReservation | Creates a new reservation. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetReservation | Returns the reservation configuration. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListReservations | Returns the list of reservations for the given project. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateReservation | Updates properties of the specified reservation. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
DeleteReservation | Deletes the specified reservation. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListReservationTopics | Lists the topics attached to the specified reservation. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 AdminServiceSettings 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
AdminServiceSettings adminServiceSettings =
AdminServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
AdminServiceClient adminServiceClient = AdminServiceClient.create(adminServiceSettings);
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
AdminServiceSettings adminServiceSettings =
AdminServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
AdminServiceClient adminServiceClient = AdminServiceClient.create(adminServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
AdminServiceClient.ListReservationTopicsFixedSizeCollection
AdminServiceClient.ListReservationTopicsPage
AdminServiceClient.ListReservationTopicsPagedResponse
AdminServiceClient.ListReservationsFixedSizeCollection
AdminServiceClient.ListReservationsPage
AdminServiceClient.ListReservationsPagedResponse
AdminServiceClient.ListSubscriptionsFixedSizeCollection
AdminServiceClient.ListSubscriptionsPage
AdminServiceClient.ListSubscriptionsPagedResponse
AdminServiceClient.ListTopicSubscriptionsFixedSizeCollection
AdminServiceClient.ListTopicSubscriptionsPage
AdminServiceClient.ListTopicSubscriptionsPagedResponse
AdminServiceClient.ListTopicsFixedSizeCollection
AdminServiceClient.ListTopicsPage
AdminServiceClient.ListTopicsPagedResponse
AdminServiceSettings
Settings class to configure an instance of AdminServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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
AdminServiceSettings.Builder adminServiceSettingsBuilder = AdminServiceSettings.newBuilder();
adminServiceSettingsBuilder
.createTopicSettings()
.setRetrySettings(
adminServiceSettingsBuilder
.createTopicSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
AdminServiceSettings adminServiceSettings = adminServiceSettingsBuilder.build();
AdminServiceSettings.Builder
Builder for AdminServiceSettings.
CursorServiceClient
Service Description: The service that a subscriber client application uses to manage committed cursors while receiving messsages. A cursor represents a subscriber's progress within a topic partition for a given subscription.
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 (CursorServiceClient cursorServiceClient = CursorServiceClient.create()) {
CommitCursorRequest request =
CommitCursorRequest.newBuilder()
.setSubscription("subscription341203229")
.setPartition(-1799810326)
.setCursor(Cursor.newBuilder().build())
.build();
CommitCursorResponse response = cursorServiceClient.commitCursor(request);
}
Note: close() needs to be called on the CursorServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
StreamingCommitCursor | Establishes a stream with the server for managing committed cursors. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
CommitCursor | Updates the committed cursor. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListPartitionCursors | Returns all committed cursor information for a subscription. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 CursorServiceSettings 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
CursorServiceSettings cursorServiceSettings =
CursorServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
CursorServiceClient cursorServiceClient = CursorServiceClient.create(cursorServiceSettings);
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
CursorServiceSettings cursorServiceSettings =
CursorServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
CursorServiceClient cursorServiceClient = CursorServiceClient.create(cursorServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
CursorServiceClient.ListPartitionCursorsFixedSizeCollection
CursorServiceClient.ListPartitionCursorsPage
CursorServiceClient.ListPartitionCursorsPagedResponse
CursorServiceSettings
Settings class to configure an instance of CursorServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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 commitCursor 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
CursorServiceSettings.Builder cursorServiceSettingsBuilder = CursorServiceSettings.newBuilder();
cursorServiceSettingsBuilder
.commitCursorSettings()
.setRetrySettings(
cursorServiceSettingsBuilder
.commitCursorSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
CursorServiceSettings cursorServiceSettings = cursorServiceSettingsBuilder.build();
CursorServiceSettings.Builder
Builder for CursorServiceSettings.
PartitionAssignmentServiceClient
Service Description: The service that a subscriber client application uses to determine which partitions it should connect to.
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 (PartitionAssignmentServiceClient partitionAssignmentServiceClient =
PartitionAssignmentServiceClient.create()) {
BidiStream<PartitionAssignmentRequest, PartitionAssignment> bidiStream =
partitionAssignmentServiceClient.assignPartitionsCallable().call();
PartitionAssignmentRequest request = PartitionAssignmentRequest.newBuilder().build();
bidiStream.send(request);
for (PartitionAssignment response : bidiStream) {
// Do something when a response is received.
}
}
Note: close() needs to be called on the PartitionAssignmentServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
AssignPartitions | Assign partitions for this client to handle for the specified subscription. The client must send an InitialPartitionAssignmentRequest first. The server will then send at most one unacknowledged PartitionAssignment outstanding on the stream at a time. The client should send a PartitionAssignmentAck after updating the partitions it is connected to to reflect the new assignment. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 PartitionAssignmentServiceSettings 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
PartitionAssignmentServiceSettings partitionAssignmentServiceSettings =
PartitionAssignmentServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
PartitionAssignmentServiceClient partitionAssignmentServiceClient =
PartitionAssignmentServiceClient.create(partitionAssignmentServiceSettings);
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
PartitionAssignmentServiceSettings partitionAssignmentServiceSettings =
PartitionAssignmentServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
PartitionAssignmentServiceClient partitionAssignmentServiceClient =
PartitionAssignmentServiceClient.create(partitionAssignmentServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
PartitionAssignmentServiceSettings
Settings class to configure an instance of PartitionAssignmentServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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 assignPartitions 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
PartitionAssignmentServiceSettings.Builder partitionAssignmentServiceSettingsBuilder =
PartitionAssignmentServiceSettings.newBuilder();
partitionAssignmentServiceSettingsBuilder
.assignPartitionsSettings()
.setRetrySettings(
partitionAssignmentServiceSettingsBuilder
.assignPartitionsSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
PartitionAssignmentServiceSettings partitionAssignmentServiceSettings =
partitionAssignmentServiceSettingsBuilder.build();
PartitionAssignmentServiceSettings.Builder
Builder for PartitionAssignmentServiceSettings.
PublisherServiceClient
Service Description: The service that a publisher client application uses to publish messages to
topics. Published messages are retained by the service for the duration of the retention period
configured for the respective topic, and are delivered to subscriber clients upon request (via
the SubscriberService
).
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 (PublisherServiceClient publisherServiceClient = PublisherServiceClient.create()) {
BidiStream<PublishRequest, PublishResponse> bidiStream =
publisherServiceClient.publishCallable().call();
PublishRequest request = PublishRequest.newBuilder().build();
bidiStream.send(request);
for (PublishResponse response : bidiStream) {
// Do something when a response is received.
}
}
Note: close() needs to be called on the PublisherServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
Publish | Establishes a stream with the server for publishing messages. Once the stream is initialized, the client publishes messages by sending publish requests on the stream. The server responds with a PublishResponse for each PublishRequest sent by the client, in the same order that the requests were sent. Note that multiple PublishRequests can be in flight simultaneously, but they will be processed by the server in the order that they are sent by the client on a given stream. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 PublisherServiceSettings 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
PublisherServiceSettings publisherServiceSettings =
PublisherServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
PublisherServiceClient publisherServiceClient =
PublisherServiceClient.create(publisherServiceSettings);
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
PublisherServiceSettings publisherServiceSettings =
PublisherServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
PublisherServiceClient publisherServiceClient =
PublisherServiceClient.create(publisherServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
PublisherServiceSettings
Settings class to configure an instance of PublisherServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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 publish 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
PublisherServiceSettings.Builder publisherServiceSettingsBuilder =
PublisherServiceSettings.newBuilder();
publisherServiceSettingsBuilder
.publishSettings()
.setRetrySettings(
publisherServiceSettingsBuilder
.publishSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
PublisherServiceSettings publisherServiceSettings = publisherServiceSettingsBuilder.build();
PublisherServiceSettings.Builder
Builder for PublisherServiceSettings.
SubscriberServiceClient
Service Description: The service that a subscriber client application uses to receive messages from subscriptions.
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 (SubscriberServiceClient subscriberServiceClient = SubscriberServiceClient.create()) {
BidiStream<SubscribeRequest, SubscribeResponse> bidiStream =
subscriberServiceClient.subscribeCallable().call();
SubscribeRequest request = SubscribeRequest.newBuilder().build();
bidiStream.send(request);
for (SubscribeResponse response : bidiStream) {
// Do something when a response is received.
}
}
Note: close() needs to be called on the SubscriberServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
Subscribe | Establishes a stream with the server for receiving messages. |
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 SubscriberServiceSettings 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
SubscriberServiceSettings subscriberServiceSettings =
SubscriberServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
SubscriberServiceClient subscriberServiceClient =
SubscriberServiceClient.create(subscriberServiceSettings);
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
SubscriberServiceSettings subscriberServiceSettings =
SubscriberServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
SubscriberServiceClient subscriberServiceClient =
SubscriberServiceClient.create(subscriberServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
SubscriberServiceSettings
Settings class to configure an instance of SubscriberServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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 subscribe 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
SubscriberServiceSettings.Builder subscriberServiceSettingsBuilder =
SubscriberServiceSettings.newBuilder();
subscriberServiceSettingsBuilder
.subscribeSettings()
.setRetrySettings(
subscriberServiceSettingsBuilder
.subscribeSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
SubscriberServiceSettings subscriberServiceSettings = subscriberServiceSettingsBuilder.build();
SubscriberServiceSettings.Builder
Builder for SubscriberServiceSettings.
TopicStatsServiceClient
Service Description: This service allows users to get stats about messages in their 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 (TopicStatsServiceClient topicStatsServiceClient = TopicStatsServiceClient.create()) {
ComputeMessageStatsRequest request =
ComputeMessageStatsRequest.newBuilder()
.setTopic(TopicName.of("[PROJECT]", "[LOCATION]", "[TOPIC]").toString())
.setPartition(-1799810326)
.setStartCursor(Cursor.newBuilder().build())
.setEndCursor(Cursor.newBuilder().build())
.build();
ComputeMessageStatsResponse response = topicStatsServiceClient.computeMessageStats(request);
}
Note: close() needs to be called on the TopicStatsServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
Method | Description | Method Variants |
---|---|---|
ComputeMessageStats | Compute statistics about a range of messages in a given topic and partition. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ComputeHeadCursor | Compute the head cursor for the partition. The head cursor's offset is guaranteed to be less than or equal to all messages which have not yet been acknowledged as published, and greater than the offset of any message whose publish has already been acknowledged. It is zero if there have never been messages in the partition. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ComputeTimeCursor | Compute the corresponding cursor for a publish or event time in a topic partition. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
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 TopicStatsServiceSettings 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
TopicStatsServiceSettings topicStatsServiceSettings =
TopicStatsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
TopicStatsServiceClient topicStatsServiceClient =
TopicStatsServiceClient.create(topicStatsServiceSettings);
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
TopicStatsServiceSettings topicStatsServiceSettings =
TopicStatsServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
TopicStatsServiceClient topicStatsServiceClient =
TopicStatsServiceClient.create(topicStatsServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
TopicStatsServiceSettings
Settings class to configure an instance of TopicStatsServiceClient.
The default instance has everything set to sensible defaults:
- The default service address (pubsublite.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 computeMessageStats 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
TopicStatsServiceSettings.Builder topicStatsServiceSettingsBuilder =
TopicStatsServiceSettings.newBuilder();
topicStatsServiceSettingsBuilder
.computeMessageStatsSettings()
.setRetrySettings(
topicStatsServiceSettingsBuilder
.computeMessageStatsSettings()
.getRetrySettings()
.toBuilder()
.setTotalTimeout(Duration.ofSeconds(30))
.build());
TopicStatsServiceSettings topicStatsServiceSettings = topicStatsServiceSettingsBuilder.build();
TopicStatsServiceSettings.Builder
Builder for TopicStatsServiceSettings.