Google PubSub: drop nacked message after n retries

2.1k views Asked by At

Is there way to configure pull subscription in the way that messages which caused error and were nacked, were re-queued (and so that redelivered) no more than n times?

Ideally on the last processing if it also failed I would like to handle this case (for example, log that this message is given up to process and will be dropped).

Or probably it's possible to find out, how much times received message was tried to be processed before?

I use node.js. I can see a lot of different options in the source code by am not sure how should I achieve desired behaviour.

2

There are 2 answers

1
Kamal Aboul-Hosn On BEST ANSWER

Currently, there is no way in Google Cloud Pub/Sub to automatically drop messages that were redelivered some designated number of times. The message will stop being delivered once the retention deadline has passed for that message (by default, seven days). Likewise, Pub/Sub does not keep track of or report the number of times a message was delivered.

If you want to handle these kinds of messages, you'd need to maintain a persistent storage keyed by message ID that you could use to keep track of the delivery count. If the delivery count exceeds your desired threshold, you could write the message to a separate topic that you use as a dead letter queue and then acknowledge original message.

0
Mahesh Gattani On

Cloud Pub/Sub supports Dead Letter Queues that can be used to drop nacked messages after a configurable number of retries.