Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does a BasicReject with requeue actually go?

Tags:

rabbitmq

This seems like a simple question, but I'm having a hard time finding a definitive answer. If in RabbitMQ 3.6.1 I have a queue that looks like this:

5  4  3  2  1  <= head

And I consume message 1, then do:

channel.BasicReject(ea.DeliveryTag, true);

Will the 1 end up on the end of the queue or at the head of the queue (assuming for the sake of simplicity that nobody else is consuming the queue at the time)? So will I end up with:

1  5  4  3  2  <= head

or:

5  4  3  2  1  <= head

And is there anyway to control it (one way would be to ack the message and repost it entirely I suppose)? I actually want the first situation because I'm rejecting 1 because a particular resource needed to process that message is currently unavailable. So I'd like to throw it back on the queue to be processed later (when the resource is available) or get picked up by somebody else (who has resources available). But I don't want to throw it back just to keep picking it up again.

like image 378
Matt Burland Avatar asked Jun 08 '16 18:06

Matt Burland


People also ask

What happens to unacknowledged messages in RabbitMQ?

RabbitMQ Unacked Messages are the messages that are not Acknowledged. If a consumer fails to acknowledge messages, the RabbitMQ will keep sending new messages until the prefetch value set for the associated channel is equal to the number of RabbitMQ Unacked Messages count.

What is RabbitMQ Requeue?

requeue: specifies whether to requeue the rejected messages. If you set this parameter to true, the rejected messages are requeued. If you set this parameter to false, the rejected messages are discarded or sent to dead-letter exchanges.

How does RabbitMQ work?

RabbitMQ is a widely used open-source message broker that helps in scaling the application by deploying a message queuing mechanism in between the two applications. It offers temporary storage for data preventing data loss. RabbitMQ Queue takes messages from the publisher and sends them to the consumer.

Is RabbitMQ exactly once?

RabbitMQ only supports at-least-once delivery (when ACKs are used) and at-most-once semantics (when ACKs aren't used).


1 Answers

I'd say the answer is here, I'll quote a part:

Messages can be returned to the queue using AMQP methods that feature a requeue parameter (basic.recover, basic.reject and basic.nack), or due to a channel closing while holding unacknowledged messages. Any of these scenarios caused messages to be requeued at the back of the queue for RabbitMQ releases earlier than 2.7.0. From RabbitMQ release 2.7.0, messages are always held in the queue in publication order, even in the presence of requeueing or channel closure.

So we could assume that RMQ is implemented in that way the messages are not deleted form the queue (physically deleted) until they are ACKed, they may have a ACKed flag or whatever.

like image 68
cantSleepNow Avatar answered Oct 08 '22 00:10

cantSleepNow