[rabbitmq-discuss] Duplicate Messages received after basicRecoveryAsync() is called.

Matthias Radestock matthias at lshift.net
Fri Feb 26 16:08:55 GMT 2010


John Mann wrote:
> By design, the RabbitMQConsumer does not acknowledge a message if the
> RawConsumer throws an exception.
> The problem is that the behavior of the RawConsumer class can change
> during runtime.  This means that it can throw an exception while
> consuming some messages, then later in time it can "recover".  When
> it recovers, I need to be able to retry all of the previously
> unacknowledged messages.
>> Would closing and re-opening the channel be an option?
> I think I can do that.  Are there any pitfalls in this approach.  I
> don't want to lose any messages.

Closing the channel will result in all unacknowledged messages getting 
requeued, so no messages will be lost.

Another option is to cancel the consumer before initiating the recover. 
The sequence of client actions would be something like this:
1) send basic.cancel
2) wait for basic.cancel-ok
3) send basic.recover
4) send basic.consume

The hook for step 2 is provided by overriding the handleCancelOk method 
on the consumer class.

Note that the basic.recover in step 3 can by async or sync - it doesn't 

While waiting for the basic.cancel-ok in step 2 you have a choice of 
either continuing to process and ack messages, or throw them away and 
let the server resend them to the client as part of the recovery.



More information about the rabbitmq-discuss mailing list