Repository navigation
Find out how often a message was nak'ed? #1093
|
I have a bit of code running to subscribe to a NATS jetstream consumer and was testing how nak (with delay) can be of value. The message handling usually involves accessing remote systems by network, which must be considered the most likely cause of failure. But there can be other problems, too. If message handling fails, for whatever reason, I want to nak a message to retry it later. To prevent messages from being nak'ed forever, I was considering a hard limit. Is there a way to find out how often a message was nak'ed? I already tried to set a custom header before the nak, but it does not survive and the next time the message is tried, the headers are empty again. Any ideas? |
Replies: 1 comment 1 reply
|
Use
For a hard limit, set |
Use
msg.metadata.num_delivered(nats-py 2.16.0, nats-server 2.12) The server counts each delivery. Headers are part of the stored message, so a nak cannot change them.nak(delay=0.2)3 times -num_deliveredis 1, 2, 3ConsumerConfig(max_deliver=3)- no 4th deliveryFor a hard limit, set
max_deliveron the consumer.