Is it safe to ack/nack messages in a different thread? #249
-
Is it safe to acknowledge or negatively acknowledge (ack/nack) messages in a different thread than the one running the await foreach loop that consumes messages from a NATS server? The below provided demo code appears to function correctly, but in my production code, I encounter an issue with message acknowledgment. The consumer loop makes a call to an external service and does not wait for result, and when the result of processing is received (in a different thread through a different endpoint), the application attempts to acknowledge the NATS message using
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
It should work. Another issue might be caused by messages buffered by the consume call, currently 1000. You could try reducing it e.g. |
Beta Was this translation helpful? Give feedback.
-
Great... I've already tested it. Works flawlessly until now! Thanks a lot for quick fixing. |
Beta Was this translation helpful? Give feedback.
I think I found it. It's a serialization bug in the library. sorry about that.
Problem is here:
In
msg.AckAsync()
we're still (wrongly) using the custom serializer serializing+ACK
instead we should use default.@robertmircea thank you so much for the repro!
edit:
minimal example: