Reputation: 4562
Background
There are two messages in my queue:
I have one channel, one consumer with Qos active with a prefetch count of 1.
Scenario
A message delivery foo
comes in, and I reject the message with requeue=true
.
Expected:
The next message that is delivered is bar
Actual:
The next message that is delivered is foo
Question:
Why does my consumer get the message it just requeued instead of the next one? And how can I get the result described above?
I expected the requeued message to be at the tail of the queue.
I've considered acknowledging and republishing the message, but that opens the risk of losing messages.
Upvotes: 2
Views: 568
Reputation: 94
From the https://www.rabbitmq.com/semantics.html
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.
Emphasis mine
Because you only have one consumer, this behaviour is expected
You could republish the message to the same queue, that would make sure the problem message ends up on the tail.
Your other option is to create a new queue for failed messages, so you can deal with them separately.
Upvotes: 4