Lin Du
Lin Du

Reputation: 102507

How to delay re-delivery message?

I am using the asynchronous pull of Cloud Pub/Sub

For now, when I call message.nack() method, it will re-delievery this message immediately.

subscription.on('message', (message) => {
  message.nack();
})

How to delay the re-delivery?

For example, I got a message with publishTime: '2019-05-28T10:24:31.055Z'

I want to let this message re-delivery 20 seconds(computed) later from last delivery.

Upvotes: 0

Views: 1911

Answers (3)

Sneha Mule
Sneha Mule

Reputation: 715

  • Pubsub guarantee at least one time delivery.
  • So unless you are not acknowledging the message, it will redeliver the infinite time.
  • It expect to acknowledge message to complete in time which specified in subscription setting(Acknowledgement deadline)

you can delay it by few setting in subscription

  1. Change Acknowledgement deadline to 600seconds(10 Minutes)
  2. Enable exactly one delivery (It will make sure once ur deadline time exceed then it will do reattempt for delivery message)
  3. Enable dead Lettering(Create topic and after 5 attempts send to new topic.)

enter image description here

Upvotes: 0

Mahesh Gattani
Mahesh Gattani

Reputation: 369

You can now configure a retry policy in your Cloud Pub/Sub subscription. Retry policy allows users to have per message exponential backoff in case of failures.

More information can be found here.

Upvotes: 0

Kamal Aboul-Hosn
Kamal Aboul-Hosn

Reputation: 17251

There is currently no way in Cloud Pub/Sub to delay the redelivery of a message. When a message is nacked, it is immediately a candidate for redelivery to the same subscriber or to another subscdriber.

Upvotes: 1

Related Questions