Search code examples
ruby-on-railsrabbitmqmessage-queuebunny

RabbitMq: Message lost from queue when exceptions occurred during message processing


I am ruby on rails developer. i am using rabbitMQ in my project to processed some data as soon as the data comes in queue. i am using bunny gem a rabbitMQ client that provide interface to interact with RabbitMq.

My issue is that whenever an exceptions occurred or server stops unexpectedly while processing data from queue my message from the queue is lost.

I want to know how people deal with lost messages from the rabbitMQ queue. is there any way to get those messages back for processing.


Solution

  • There is no way to get the messages back when they're lost. Maybe you could try and track down some entries in RMQ's database cache - but that's just a wild guess/long shot and I don't think that it will help.

    What you do need to do for the future is:

    • in case you are using a single server: make the queues and messages durable, and explicitly acknowledge (so switch off the auto-ACK flag) messages on consumer side only once they're processed.
    • in case you are using cluster of RMQ nodes (which is of course recommended exactly to avoid these situations): set up queue mirroring

    Take a look at RMQ persistance and high availability.