Messages produced by a single producer to a single destination
will be seen by a consumer in that destination in the same order as they were
produced. However, certain events, such as system failures, can disrupt this
order. Message ordering allows you to prevent this order being changed.
Message reordering can be avoided if the following rules are applied:
- All the messages produced have the same priority.
- All the messages produced have the same reliability and that reliability
is greater than best effort nonpersistent (for more information
about reliability levels see Message reliability levels).
Note that if messages are produced with a reliability of anything less than assured
persistent, it is possible for sequences of messages to be redelivered
after a failure, however their underlying order will be maintained. For example,
messages may arrive in the following sequence: 1, 2, 3, 2, 3, 4.
- The producer is single threaded (as supported by the JMS API).
- If the destination is a queue, it is not
assigned to a cluster bus member with more than one messaging engine.
- The destination is in the same bus as the producer, otherwise it is possible
for some messages to be routed to an exception destination when arriving in
the destination's bus, for example if the destination is temporarily full.
If the destination and the producer are in different buses the route from
the producer's bus to the destination's bus must not be altered.
- The destination has no exception destination defined, otherwise it is
possible for some messages to be delivered to the exception destination under
certain failure scenarios. These messages may then be processed out of order.
- The consumer does not deliberately alter the order of messages retrieved,
for example by changing its selector.
- If the destination is a queue, only one consumer is consuming from it.
If the consumer cannot be guaranteed to be connected to the messaging engine
that owns the queue point of the queue, the queue must be defined as Receive
exclusive.
- If the destination is a topic space and the consumer's subscription is
nondurable, ordering is not guaranteed across separate instances of the subscription.
- If the destination is a topic space the consumer's subscription is not
created with the Share Durable Subscriptions property
set to permit sharing.
These rules assure correct ordering of the messages consumed by a single
consumer, however they do not guarantee that the consumer will receive all
messages produced by the producer. Whether the consumer receives all messages
can be affected for a number reasons, including the reliability of the messages
and the consumer's selection criteria.