Unless you redeliver.. the messages are consumed at the same order of the producer.
Now, if you do something like this:
producer1 (thread 1)
producer2 (thread 2)
we gurantee that msg_2_2 will be delivered after msg_2_1, and msg1_2 will be delivered after msg1_1
if you need to stick the order of the producers together (I,e, msg1_1 and msg1_2 to stick together no matter what), then you need to take a look at message-grouping which will place a few more boundaries on these deliveries.
thank you for your answer.
Let me further clarify our case.
We don't have parallel threads/concurrent producers. Each producer runs sequentially, some time after the previous one has completed its job and is terminated. Thus, at any given time, only one producer instance is alive and sending messages to the topic. The producer code called to send messages is always the same, we refer to different producers only because we have a new JMS session.
More specifically, based on your example, we assure that thread2 runs after the completion of thread1. In this case, we would like to know if it is guaranteed that msg_2_1 will be consumed in a timely order, i.e. after 1_2 and before 2_2.
Our scenario, in more detail, is the following:
1) Ordered sending of messages to the topic:
Producer P1 sends two messages to the topic, in the following order:
1st message sent: msg1_1, second message sent: msg1_2
P1 dies (session is terminated).
We assume that the topic at this moment contains: msg1_2, msg1_1 and any consumer that would receive messages, would first receive msg1_1 and then msg1_2.
After a while, producer P2 is spawned.
P2 sends another two messages to the same topic, in the following order:
1st message sent: msg2_1, second message sent: msg2_2
2) Multiple Consumers have been subscribed to the Topic. Assuming that a consumer C1 starts receiving messages after P2 has died, what will the order of messages C1 will consume be?
Is it guaranteed that the order of messages received by C1 will be as follows?
1st message received: msg1_1
2nd message received: msg1_2
3rd message received: msg2_1
4th message received: msg2_2
Many thanks again,
like clebert says ordering is gauranteed between a single producer and consumer(s). Theres nothing in the spec that defines ordering between multiple producers and consumers, however, if you can gaurantee that the first producer has sent and had acknowledged its messages before the second then you can assume the order holds.