Elad Benda
Elad Benda

Reputation: 36674

how to set timeout to google pubsub publisher and subscriber?

In my java code I use Google -pubsub.

how can i set a timeout for

subscriber - wait for messages until timeout expires? (how can i set a retry policy?)

publisher - wait till message is sent for timeout time. (how can i set a retry policy?)

I saw this post but didn't manage to translate the js post to java

Here is how i set my sub

    final Subscriber subscriber = Subscriber
            .defaultBuilder(subscriptionName, receiver)
            .setChannelProvider(channelProvider)
            .build();

and pub

    final Publisher publisher = Publisher.defaultBuilder(topicName)
            .setChannelProvider(channelProvider)
            .build();

Upvotes: 1

Views: 7901

Answers (1)

Kamal Aboul-Hosn
Kamal Aboul-Hosn

Reputation: 17251

With the latest Cloud Pub/Sub client library, you do not need to set timeouts or retry policies in the Subscriber. These are handled under the hood for you and you just need to pass your MessageReceiver into defaultBuilder. When messages are available, they will be sent to receiveMessage. If your subscribing stops for any non-retryable reason, then the Subscriber will be shut down. You can listen for these notifications by calling addListener on your Subscriber.

On the Publisher, you can use setRetrySettings in the Builder. In particular, you'd want to setTotalTimeout on RetrySettings.Builder. The Publisher will retry publish calls on retryable errors up to this total deadline.

Upvotes: 1

Related Questions