Sometimes it can be useful to ensure that every topic consumer sees messages arriving on the topic in exactly the same order. Normally we guarrentee the broker will guarantee the order of all messages sent by the same producer; however due to multi-threading . However, owing to the broker's use of multiple threads and asynchronous processing, the messages from different producers could arrive in different consumers in different orders. e.g. For example, if we have producers producers P and and Q sending messages such that at about the same time time P sends P1 , P2 , P3 and and Q sends Q1 , Q2 . Then 2 different consumeres Therefore, two different consumers could see messages arrive in this order...the following order:
Code Block |
consumer1: P1 P2 Q1 P3 Q2
consumer2: P1 Q1 Q2 P2 P3
|
i.e. each producers messages are in order; but In this example each producer's message's are in self-relative order. However, the streams of messages across producers can get intermixed. Total orderingOrdering of a destination in ActiveMQ ensures that each consumer will see the same total order on that topic. This has a peformance performance cost, since more greater synchronization is required, but . This can be useful - e.g. particularly in times when you want to implement , particularly when very fast optimistic transactions are required. With total ordering the messages would arrive like this...:
Code Block |
consumer1: P1 P2 Q1 P3 Q2
consumer2: P1 P2 Q1 P3 Q2
|
Configuring Total Ordering Enable the the <strictOrderDispatchPolicy/> on the Per Destination Policies. Here's an example
Code Block |
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">">
<dispatchPolicy>
<strictOrderDispatchPolicy />
</dispatchPolicy>
</policyEntry>
</policyEntries>
</policyEntries></policyMap>
</destinationPolicy>
|
|