Search code examples
activemq-classicamqp

activemq amqp message order preservaton


I am having trouble with the ambiquity of this statement:

http://activemq.apache.org/how-do-i-preserve-order-of-messages.html

If you have multiple consumers on a single queue the consumers will compete for messages and ActiveMQ will load balance across them, so order will be lost.

Does this mean that if I one producer (P1) publshing on a single topic (T1) and four subscribers to that topic (S1,S2,S3, S4). All above using AMQP.

Is there is no guarantee that the message order from P1 would be seen by S1 in that same order by itself?

And each other subscriber would not necessarily see the order than P1 actually sent?).

Note, I am talking about jms pub/sub here via topic://

[If I add more producers but each one has its own topic queue, would that also effect the order on the other queues?]

I would not expect this, but the statement from the website is giving us some concerns here.


Solution

  • The documentation is actually fairly clear:

    ActiveMQ will preserve the order of messages sent by a single producer to all consumers on a topic. If there is a single consumer on a queue then the order of messages sent by a single producer will be preserved as well.

    Since you are asking about Topics the first sentence pretty much nails it down for you, for Topics, order is preserved when there is one producer. Each subscriber on a Topic sees each message sent and sees it in the order it was sent (barring any priority based reordering). Only when you are talking about Queues (not Topics) does the ordering become more complex.

    For a Queue you are no longer doing pub/sub you are doing point-to-point and in that case multiple subscribers compete for messages from the Queue and thus you no longer have an order guarantee since each consumer will be taking some messages and depending on prefetch they will take them in some batches which you cannot predict.