googleapis / nodejs-pubsub

Node.js client for Google Cloud Pub/Sub: Ingest event streams from anywhere, at any scale, for simple, reliable, real-time stream analytics.
https://cloud.google.com/pubsub/
Apache License 2.0
516 stars 227 forks source link

PubSub: sending failing message to deadletter topic without retries #1908

Closed vvoicehovics closed 2 months ago

vvoicehovics commented 3 months ago

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:

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

hongalex commented 2 months ago

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.