这是indexloc提供的服务,不要输入任何密码
Skip to content

docs(sample): Update the subscribe with error listener and subscribe with exactly-once samples #2437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,11 @@ public static void subscribeWithErrorListenerExample(String projectId, String su
.setExecutorProvider(executorProvider)
.build();

// Listen for unrecoverable failures. Rebuild a subscriber and restart subscribing
// when the current subscriber encounters permanent errors.
// Listen for unrecoverable failures.
subscriber.addListener(
new Subscriber.Listener() {
public void failed(Subscriber.State from, Throwable failure) {
System.out.println(failure.getStackTrace());
if (!executorProvider.getExecutor().isShutdown()) {
subscribeWithErrorListenerExample(projectId, subscriptionId);
}
System.out.println("Unrecoverable subscriber failure:" + failure.getStackTrace());
}
},
MoreExecutors.directExecutor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ public static void subscribeWithExactlyOnceConsumerWithResponseExample(

Subscriber subscriber = null;
try {
subscriber = Subscriber.newBuilder(subscriptionName, receiverWithResponse).build();
// Pub/Sub's exactly once delivery guarantee only applies when subscribers connect to the
// service in the same region.
// For list of locational endpoints for Pub/Sub, see
// https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints
subscriber =
Subscriber.newBuilder(subscriptionName, receiverWithResponse)
.setEndpoint("us-west1-pubsub.googleapis.com:443")
.build();
// Start the subscriber.
subscriber.startAsync().awaitRunning();
System.out.printf("Listening for messages on %s:\n", subscriptionName.toString());
Expand Down