Sending a second message after confirming the first. Does RabbitMQ guarantee an order?

Suppose that several manufacturers publish the same exchange E (branching). Each manufacturer has its own channel. Queue Q is associated with the exchange E. producer P1 publishes a message M1-E and receives a confirmation A1 from E. Only after confirmation A1 does the second producer P2 publish a second message M2. Does RabbitMQ follow the message order in Q: M1, M2 - second? That is, they will subscribe to the Q-consumer, always receiving M1, and after that M2?

+5
source share
1 answer

RabbitMQ guarantees the order of messages in the queue: First In, First Out. The first message to enter the queue will be the first message to exit the queue, and they will remain in order (assuming you just consume and toss them ... if you start a nacking / rejecting message, republishing them, etc., things change)

This is the only guarantee he will make in message order: FIFO queues.

If you need to guarantee an order that messages are delivered to the queue, you must create this process yourself.

FWIW, It is very difficult to build this guarantee. The only really guaranteed way to ensure message order is to not send the next one until the first one is processed.

Even if you are waiting for publisher confirmation before sending the next one, it is possible that the next one will be in line in the queue before the first one (although this is unlikely).

You can see Message Sequence and Resequencer if you need to ensure that the client receives messages in a specific order.

+1
source

Source: https://habr.com/ru/post/1244060/


All Articles