I have a business process that receives an order from a RabbitMQ queue. I was thinking about not acknowledging it (meaning, leave it in the queue) for potentially a long time (>10 minutes) and only then either removing it (acknowledging) or not (not acknowledging). Does this make sense? What would be the best way to deal with long running processing on top of RabbitMQ tasks?
1 Answers
In general this is ok to do. I've done this a number of time, and it has a few advantages such as if your process crashes, the unack'd message will go back in to the queue and be picked up again later
there are some potential downsides to this, though.
for one, it is possible to overload your server with unack'd messages. be sure to set a consumer prefetch limit to prevent that from happening
it's also possible to have processes that should not be restarted once they are running. i have a lot of processes like this... things that kick off external server processes, like long-running database database with Oracle. in situations like this, it is best to ack the message right away and use a status update queue of some kind to know when the process is done.
over-all, there is no "best way" to handle long running tasks... there are no best practices at all. every practice we use has potential benefit and potential detriment. the real trick is to understand which scenarios work best with which practice. you need to evaluate the pro's and con's of this approach for your scenario.

- 72,004
- 22
- 206
- 219
-
Thanks! BTW, what would be your recommended book on RabbitMQ? – Ricardo Peres Sep 21 '15 at 13:11
-
everyone should have "RabbitMQ In Action" - great book all around. I have written a couple of short ebooks, too https://leanpub.com/rabbitmq-structures-and-layout and https://leanpub.com/rmq-patterns . and if you want the real deep understanding of messaging patterns and practices, pick up "Enterprise Integration Patterns". – Derick Bailey Sep 21 '15 at 13:19
-
But I seem to be unable to return the message to the queue, it os being BasicAcked automatically, even with noAck ser to true. How can I do this? – Ricardo Peres Sep 23 '15 at 04:56
-
no ack must be set to false. the language of this variable is backward. be sure to read the docs for whatever library you are using, to make sure you get the right setting, though. some libraries rename it to make more sense. – Derick Bailey Sep 23 '15 at 12:19