[rabbitmq-discuss] Queue Ordering after restart

73 views
Skip to first unread message

rathi

unread,
Dec 1, 2010, 10:41:53 AM12/1/10
to rabbitmq
In the rabbitmq documentation it is said

I have read that RabbitMQ preserves the order of messages in queues. Is this correct?

For the most part, yes. Say a publisher publishes messages M1, M2, M3 and M4 (in that order) on the same channel and with the same routing information. If these messages are routed to a queue then they will end up in the same order that they were published. Consuming on the queue will yield M1, M2, M3 and then M4.

However, the order is only guaranteed in the absence of requeuing. A message will be implicitly requeued if a consumer closes the channel before ack'ing a message. For example, if a consumer receives M1, fails to ack and closes the channel then the next consumer will receive messages in the order M2, M3, M4, M1. Messages can also be explicitly requeued if the consumer calls basic.recover{requeue=true}. The FAQ on at least once delivery talks about this in some more detail.       


I have only one consumer which should process messages in the order they are published. If my consumer gets M1 and crashes without acknowledging M1, then when I restart my consumer I want to process messages in the same order as they were published. Can this be achieved ? 


thanks & regards,

ritesh rathi

John DeTreville

unread,
Dec 1, 2010, 7:35:05 PM12/1/10
to rabbitmq...@lists.rabbitmq.com
On Dec 1, 2010, at 2:51 PM, rathi <rites...@gmail.com<mailto:rites...@gmail.com>> wrote:

From: rathi <rites...@gmail.com<mailto:rites...@gmail.com>>
Date: December 1, 2010 7:41:53 AM PST
To: rabbitmq <rabbitmq...@lists.rabbitmq.com<mailto:rabbitmq...@lists.rabbitmq.com>>
Subject: [rabbitmq-discuss] Queue Ordering after restart

I have only one consumer which should process messages in the order they are published. If my consumer gets M1 and crashes without acknowledging M1, then when I restart my consumer I want to process messages in the same order as they were published. Can this be achieved ?

I should first point out that I work in RabbitMQ's Pacific Rim office, 8 time zones away from London. I answer questions in the middle of their night. I may be trading off accuracy for promptness.

That said, I believe you cannot. I believe that if your application crashes (or closes its connection) without acknowledging a message, and the queue is persistent, then the message may later appear out of order.

More generally, if your application crashes K times without acknowledging messages, then those K messages may later appear out of order.

Cheers,
John

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq...@lists.rabbitmq.com
https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

John DeTreville

unread,
Dec 1, 2010, 7:49:42 PM12/1/10
to rabbitmq...@lists.rabbitmq.com
On Dec 1, 2010, at 9:30 AM, Christian Legnitto <cleg...@mozilla.com<mailto:cleg...@mozilla.com>> wrote:

From: Christian Legnitto <cleg...@mozilla.com<mailto:cleg...@mozilla.com>>
Date: December 1, 2010 9:30:11 AM PST
To: Matthew Sackman <mat...@rabbitmq.com<mailto:mat...@rabbitmq.com>>
Cc: "rabbitmq...@lists.rabbitmq.com<mailto:rabbitmq...@lists.rabbitmq.com>" <rabbitmq...@lists.rabbitmq.com<mailto:rabbitmq...@lists.rabbitmq.com>>
Subject: Re: [rabbitmq-discuss] Routing key questions/suggestions

Ok, thanks for the info guys. I had a long reply but I guess it didn't go through yesterday. I'll send it anyway just for posterity.

The following is just opinion, but since it's \my/ opinion, it's \very/ interesting!

It might be best (in some future world) to let routing keys and binding keys be \lists/ of strings, pre-parsed by the client. If RabbitMQ doesn't have to interpret separator characters, it can't get it wrong!

(That said, this would be an extension to the AMQP protocol, but all of these other suggestions would be extensions too.)

Cheers,
John DeTreville
RabbitMQ Pacific Rim office
(8 hours behind London time)
(but just as cold and dark)

Reply all
Reply to author
Forward
0 new messages