blob: 33ef56318d6db4989cbea00aee2d5b35dc92303d [file] [log] [blame]
<div class="wiki-content maincontent"><h2>Overview</h2><p>From ActiveMQ v4: the choice of a broker performing synchronous or asynchronous dispatch to a consumer has become more configurable. It is now configured as a default value on the <link><page ri:content-title="Connection Configuration URI"></page><plain-text-link-body>connection URI, Connection and ConnectionFactory</plain-text-link-body></link> as well as with being customizable on a per consumer basis via the <link><page ri:content-title="Destination Options"></page></link> instead previously just being a transport server setting.</p><p>This makes more sense since you want to do asynchronous message delivery to slower consumers, but synchronous message delivery for faster consumers (to avoid the synchronization and context switching costs of adding another SEDA queue). The downside to using synchronous message delivery is that the producer is more likely to block if there is a slow consumer that he is dispatching messages to.</p><p>The default setting is&#160;<strong><code>dispatchAsync=true</code></strong> which is the best setting for high performance. If you want to deal better with slow consumers you will want to enable this setting. If you want better throughput and the chances of having a slow consumer are low, you may want to change this to <strong><code>dispatchAsync=false</code></strong>.</p><h3>Configuring Async Dispatch at the ConnectionFactory Level</h3><structured-macro ac:macro-id="b6c7c4b9-0a3b-4d23-9106-5b97ec057de0" ac:name="code" ac:schema-version="1"><parameter ac:name="">java</parameter><plain-text-body>((ActiveMQConnectionFactory)connectionFactory).setDispatchAsync(false);
</plain-text-body></structured-macro><h3>Configuring Dispatch Async at the Connection Level</h3><p>Configuring the&#160;<strong><code>dispatchAsync</code></strong> setting at this level overrides the settings at the connection factory level.</p><h3>Configuring Dispatch Async at the Consumer Level using the Destination URI</h3><p>Configuring the&#160;<strong><code>dispatchAsync</code></strong> using <link><page ri:content-title="Destination Options"></page></link> overrides the settings at the connection and connection factory level.</p><structured-macro ac:macro-id="1c757d6c-8c52-4ae7-bb24-8a4c1d6d3f47" ac:name="code" ac:schema-version="1"><parameter ac:name="">java</parameter><plain-text-body>queue = new ActiveMQQueue("TEST.QUEUE?consumer.dispatchAsync=false");
consumer = session.createConsumer(queue);
</plain-text-body></structured-macro><h3>Disabling Async Dispatch on Broker's Transport Connector</h3><p>It is possible to disable async dispatch on a specific transport connector via the&#160;<strong><code>disableAsyncDispatch</code></strong> property. Once disabled for this transport, it cannot be enabled by individual clients.</p><structured-macro ac:macro-id="c0d99739-d154-47e1-b5e2-06cf41a2c071" ac:name="code" ac:schema-version="1"><parameter ac:name="language">xml</parameter><plain-text-body>&lt;transportConnector name="openwire" uri="tcp://0.0.0.0:61616" disableAsyncDispatch="true"/&gt;
</plain-text-body></structured-macro><p>&#160;</p><p>&#160;</p><p>&#160;</p></div>