Assume several producers publish to the same exchange E (fanout). Each producer has its own channel. Queue Q is bound to exchange E. producer P1 publishes message M1 to E and receives acknowledge A1 from E. Only after acknowledge A1 second producer P2 publishes second message M2. Does RabbitMQ guarantie order of messages in Q: M1 is first, M2 is second? That is will subscribed to Q consumer always receive M1 and after that M2?
RabbitMQ guarantees order of messages in a queue: First In, First Out. The first message to go into the queue will be the first message to come out of the queue, and they will remain in order (assuming you are just consuming and acking them... if you start nacking / rejecting message, re-publishing them, etc, things change)
That is the only guarantee that it will make on the order of messages: FIFO Queues.
If you need to guarantee the order that messages are delivered to a queue, you have to build that process yourself.
FWIW, it's very difficult to build this guarantee. The only truly guaranteed way to ensure the order of messages is not to send the next one until after the first one has been processed.
Even if you wait for the publisher acknowledgement before sending the next one, it is possible for the next one to end up in the queue before the first one (though it is highly unlikely).
You may want to look into Message Sequence and Resequencer if you need to guarantee the client gets messages in a certain order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With