com.google.cloud.pubsublite
com.google.cloud.pubsublite.cloudpubsub
com.google.cloud.pubsublite.cloudpubsub.internal
com.google.cloud.pubsublite.internal
com.google.cloud.pubsublite.internal.testing
com.google.cloud.pubsublite.internal.wire
com.google.cloud.pubsublite.proto
com.google.cloud.pubsublite.v1
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);
}