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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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().
The surface of this class includes several types of Java methods for each of the API's methods:
- A "flattened" method. With this type of method, the fields of the request type have been converted into function parameters. It may be the case that not all fields are available as parameters, and not every API method will have a flattened method entry point.
- A "request object" method. This type of method only takes one parameter, a request object, which must be constructed before the call. Not every API method will have a request object method.
- A "callable" method. This type of method takes no parameters and returns 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.