googleapis/nodejs-pubsub

PubSub: sending failing message to deadletter topic without retries

vvoicehovics opened this issue · 1 comments

Hi,

I have a service that processes many (potentially millions) of pubsub messages via a pull subscription. I have configured a deadletter topic for the subscription with retry policy having 5 retries. Suppose I receive an unprocessable message. This can happen due to various reasons, e.g. validation (i do use schemas, but not all complex field validation can be handled by a schema) or some further missing configuration required for the message to be processed or anything that i know is not transient.

Hence, ideally i would like to

  1. do a "terminalNack()" which would send the message to deadletters immediately
  2. On a related performance note, set number of max_attempts to < 5

Otherwise i needlessly do x5 work.

I could manually publish the message to deadletters, but:

  • i need to do ack() for the message to not be redelivered, which messes pubsub metrics creating a false impression that the message was processed correctly
  • is harder to use, e.g. need to create publishing client
  • when message is republished can lose original message properties (like CloudPubSubDeadLetterSourceDeliveryCount and alike)

Strangely i cannot find much info on this. What's the suggested approach? Is this use case so original / am i doing something unexpected?

do a "terminalNack()" which would send the message to deadletters immediately

The behavior you're describing isn't currently supported by Cloud Pub/Sub. If you would like to suggest this as an improvement, please file a ticket here: https://issuetracker.google.com/issues/new?component=187173&template=1162763 We do not have guarantees on when we will implement issues, but issues that have higher number of requests will generally be prioritized.

In the meantime, your workaround seems like the best bet. Re: original message properties, you can copy this over to the message attributes map, though if you aren't retrying the message, then DeliveryCount will likely be 1 anyway.