[rabbitmq-discuss] Replay order

Matthias Radestock matthias at lshift.net
Fri Aug 1 15:11:12 BST 2008


Petr Sturc wrote:
> the 1.4.0 "Release highlights" is mentioning that there is bugfix for
> "maintain message order on persister replay".
> Does it mean the messages are replayed in the same order there way sent?

Following the bugfix, the ordering guarantees provided by AMQP are 
preserved in the event of a replay of persisted messages after a broker 

AMQP's ordering guarantees are fairly straightforward at first glance 
but turn out to be surprisingly tricky to pin down precisely. Here's an 
attempt at doing the latter, courtesy of my colleague Tony 
Garnock-Jones. Take a deep breath ...


AMQP's transports MUST preserve the order of AMQP commands issued on a 
single channel, meaning that one command (such as a basic.publish, or a 
basic.deliver) can be seen to arrive before or after another carried on 
the same channel.

Let M1 and M2 be two messages, published
  - at the same message priority
  - via the same channel
  - to the same exchange.

Let us examine the case where M1 arrives at the server before M2.

If a particular queue should wind up with copies of both M1 and M2, and 
further if both M1 and M2 are to be sent from that queue
  - down the same channel
  - using basic.deliver
  - with the same consumer-tag,
then the basic.deliver carrying M1 MUST be sent before the basic.deliver 
carrying M2, unless the "redelivered" flag happens to be set on one or 
both of the basic.deliver commands.

If two basic.get operations are issued in sequence
  - on the same channel
  - reading from the same queue, and
  - those two basic.get operations happen to retrieve M1 and M2,
then M1 MUST be returned by the first basic.get-ok, and M2 MUST be 
returned by the second basic.get-ok, unless the "redelivered" flag 
happens to be set on one or both of the basic.get-ok commands.

In all situations not covered by the text above, the server is under no 
obligation to preserve ordering between M1 and M2, but MAY do so.


Simple, isn't it? ;)

  > I am playing with single producer and two consumers taking messages
> from the same queue without ACK. I am receiving them in round-robin
> order as expected. When I stop the consumers and connect another one
> WITH ACK, the messages are redelivered, but with no particular order.
> Is it correcect behavour? How does it correspond to the claim about
> maintaining message order?

As noted above, order may not be preserved for redelivered messages.



More information about the rabbitmq-discuss mailing list