[rabbitmq-discuss] What happens to messages delivered just before canceling consume?

Emile Joubert emile at rabbitmq.com
Fri May 18 10:44:00 BST 2012


Hi,

On 17/05/12 18:33, Chris wrote:
> At some point in my consume loop, after acking a message, I need to
> stop consuming (temporarily). I will have multiple consumer processes
> running and the others must pick up the slack while this one is out of
> the loop. I am using a prefetch count of 1, so I assume it's possible
> for there to be 1 additional message delivered to my consumer *after*
> I ack the final message, but *before* I cancel the consumer.

The prefetch count determines how many unacknowledged messages a
consumer is allowed to hold. Yes, it is possible for another delivery to
reach the consumer after sending the ack and before receiving the
cancel-ok.

> I have 2 questions regarding this additional message:
>  1. If I do nothing, will it be eventually returned to the queue for
> processing by another consumer?

Unacknowledged messages will be returned to the broker when the channel
is closed, or is any of these methods are invoked with requeue:
basic.recover, basic.reject and basic.nack.

>  2. After doing basic.cancel to stop my consumer, can I read in the
> aditional message and nack it, returning it to the queue?

Yes, nack with requeue. Alternatively you could cancel the subscription
before acknowledging the last message. Another option is to turn off
prefetching (prefetch = 0). If you need more precise control over when
clients may receive messages, and you don't care about throughput then
consider using basic.get.

-Emile



More information about the rabbitmq-discuss mailing list