Reputation: 7236
Recently a colleague of mine said this:
When using different sessions for producing and consuming messages, there's no guarantee that messages are delivered in the same order in which they are produced.
Now I know that JMS does not guarantee message delivery order in general, but this 'multiple sessions' angle is new to me. Is there any truth to this?
Upvotes: 1
Views: 524
Reputation: 570
As JMS is “asynchronous”, there is never any guarantee of message delivery order.
Upvotes: 1
Reputation: 308131
According to the JMS Spec (section 4.4.10 Message Order) only the order of messages sent from a session to a destination is guaranteed (and even then with some caveats).
This means:
Only the order of two messages sent from one session to the same destination is defined.
Note that it's possible that a given JMS implementation will usually deliver items in the (global) order in which they are produced. But you should not rely on this in any way, since it's basically a "best effort" thing: if they can manage it, it's usually better. If they can't, they are still well within the specification and your application must be able to handle that.
tl;dr Yes, your colleague is correct. Note again that even the guarantee in the one-session/one-destination case is not very strong, particularly if different message options are involved (see the linked PDF for details).
Upvotes: 2