问题
I want to handle unsuccessful messages the consumer gets from the queue and re-queue them.
Imagine I have a situation like this:
P => | foo | bar | baz | => C
Where foo, bar and baz are messages.
If consumer reads baz
but something goes wrong i can either use the basic.reject
or the basic.nack
( https://www.rabbitmq.com/nack.html ). Using one of these two commands, I will pass the argument to requeue the message.
The problem is the message is requeued in the same position it was before, so the next message will be baz
again.
I would like to requeue it but send it back to the beginning of the queue:
P => | baz | foo | bar | => C
I solved with some lines of code on my application, but I wonder if a better solution exists, maybe using some functionality of RabbitMQ directly.
回答1:
you can take a look on the Dead Letter Queue(DLQ): https://www.rabbitmq.com/dlx.html
来源:https://stackoverflow.com/questions/43249811/nack-and-reject-on-rabbitmq