blob: b98d2db0a2061630826230683c373e6743c12341 [file] [log] [blame]
<div class="wiki-content maincontent"><p>Sometimes it can be useful to ensure that every topic consumer sees messages arriving on the topic in exactly the same order. Normally the broker will guarantee the order of all messages sent by the same producer. However, owing to the broker's use of multiple threads and asynchronous processing, messages from different producers could arrive in different consumers in different orders.</p><p>For example, if we have producers&#160;<strong><code>P</code></strong> and&#160;<strong><code>Q</code></strong> sending messages such that at about the same time&#160;<strong><code>P</code></strong> sends <strong><code>P1</code>, <code>P2</code></strong>,&#160;<strong><code>P3</code></strong> and&#160;<strong><code>Q</code></strong> sends <strong><code>Q1</code>, <code>Q2</code></strong>. Therefore, two different consumers <em>could</em> see messages arrive in the following order:</p><structured-macro ac:macro-id="45e8d2f6-6957-4958-a4e0-e6984dc66a86" ac:name="code" ac:schema-version="1"><plain-text-body>consumer1: P1 P2 Q1 P3 Q2
consumer2: P1 Q1 Q2 P2 P3
</plain-text-body></structured-macro><p>In this example each producer's messages are in self-relative order. However, the streams of messages across producers can get intermixed.</p><p><em>Total Ordering</em> of a destination in ActiveMQ ensures that each consumer will see the same total order on that topic. This has a performance cost, since greater synchronization is required. This can be useful, particularly when very fast optimistic transactions are required. With total ordering the messages would arrive like this:</p><structured-macro ac:macro-id="34a87d6f-917a-46d7-bc5c-bd6e5b5972a8" ac:name="code" ac:schema-version="1"><plain-text-body>consumer1: P1 P2 Q1 P3 Q2
consumer2: P1 P2 Q1 P3 Q2
</plain-text-body></structured-macro><h2>Configuring Total Ordering</h2><p>Enable the&#160;<strong><code>&lt;strictOrderDispatchPolicy/&gt;</code></strong> on the <link><page ri:content-title="Per Destination Policies"></page></link>. Here's an example</p><structured-macro ac:macro-id="1ed4c58a-7249-42d8-aeba-968eb69a97ef" ac:name="code" ac:schema-version="1"><plain-text-body>&lt;destinationPolicy&gt;
&lt;policyMap&gt;
&lt;policyEntries&gt;
&lt;policyEntry topic="&gt;"&gt;
&lt;dispatchPolicy&gt;
&lt;strictOrderDispatchPolicy/&gt;
&lt;/dispatchPolicy&gt;
&lt;/policyEntry&gt;
&lt;/policyEntries&gt;
&lt;/policyMap&gt;
&lt;/destinationPolicy&gt;</plain-text-body></structured-macro></div>