[rabbitmq-discuss] Handling Undelivered messages in rabbitmq

Emile Joubert emile at rabbitmq.com
Thu Jan 6 10:58:32 GMT 2011

Hi Prashant,

On 06/01/11 09:15, Prashant Yadav wrote:

> *1)*Publish the messages with Mandatory and Immediate flag sent
> *channel.basicPublish 'exchange' ,'rKey',true,false, props,"Hello
> World".bytes*

The 'false' in that call should be 'true' if you want 'immediate' set.

> *2)*The consumer consumes even marked ( I have put numbers from 1..10 as
> marked value in header of each messages) and does not ACKS odd numbered
> messages.**
> *3)*I have implemented setReturnListnere in the publisher to capture
> undelivered messages.**
> While am able to get the number of unack messages via Rabbmitmqctl
> list_queues messages_unacknowledged, somehow my handleBasicReturn method
> does not gets called. Am in missing something.

In your case the 'mandatory' flag will cause handleBasicReturn to be 
called only if the message cannot be routed, i.e.  the message ends up 
in 0 queues. But your messages can be routed so handleBasicReturn won't 
be called.

If you had 'immediate' set and there were no consumers registered on any 
of the relevant queues then handleBasicReturn would be called. But you 
do have consumers registered so handleBasicReturn won't be called.

You could make use of the 'redelivered' flag upon message delivery to 
check whether processing has already been attempted and act accordingly.

You could republish messages to success and failure queues after 
processing, depending on the outcome and depending on how you want to 
treat failed messages.


Of possible interest is the ability of the management and monitoring 
plugin to report the number of unacknowledged messages.
See http://www.rabbitmq.com/management.html .

You can also retrieve queue depth over AMQP in the queue declare-ok 
return value after passively declaring a queue.



More information about the rabbitmq-discuss mailing list