blob: 8e20b90d069e1e68ae53e88cd1526a0c97cc9ad9 [file] [log] [blame]
<div class="wiki-content maincontent"><h2>Background</h2><p>ActiveMQ supports sending messages to a broker in sync or async mode. The mode used has a huge impact in the latency of the send call. Since latency is typically a huge factor in the throughput that can achieved by producer, using async sends can increase the performance of your system dramatically.</p><p>The good news is that ActiveMQ sends message in async mode by default in several cases. It is only in cases where the JMS specification required the use of sync sending that we default to sync sending. The cases that we are forced to send in sync mode are when persistent messages are being sent outside of a transaction.</p><p>If you are not using transactions and are sending persistent messages, then each send is synch and blocks until the broker has sent back an acknowledgement to the producer that the message has been safely persisted to disk. This ack provides that guarantee that the message will not be lost but it also costs a huge latency penalty since the client is blocked.</p><p>Many high performance applications are designed to be tolerate a small amount of message loss in failure scenarios. If your application has been designed in this fashion, you can enable the use of async sends to increase throughput even when using persistent messages.</p><h3>Configuring Async Send using a Connection URI</h3><p>You can use the <link><page ri:content-title="Connection Configuration URI"></page></link> to configure async sends as follows</p><structured-macro ac:macro-id="bc12bc02-703c-484c-910d-2e32a9a0ec5b" ac:name="code" ac:schema-version="1"><parameter ac:name="">java</parameter><plain-text-body>cf = new ActiveMQConnectionFactory("tcp://locahost:61616?jms.useAsyncSend=true");
</plain-text-body></structured-macro><h3>Configuring Async Send at the ConnectionFactory Level</h3><p>You can enable this feature on the <a shape="rect" href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/org/apache/activemq/ActiveMQConnectionFactory.html">ActiveMQConnectionFactory </a> object using the property.</p><structured-macro ac:macro-id="f193f85f-3401-4dd5-a594-dbc3128f51c4" ac:name="code" ac:schema-version="1"><parameter ac:name="">java</parameter><plain-text-body>((ActiveMQConnectionFactory)connectionFactory).setUseAsyncSend(true);
</plain-text-body></structured-macro><h3>Configuring Async Send at the Connection Level</h3><p>Configuring the dispatchAsync setting at this level overrides the settings at the connection factory level.</p><p>You can enable this feature on the <a shape="rect" href="http://incubator.apache.org/activemq/maven/activemq-core/apidocs/org/apache/activemq/ActiveMQConnection.html">ActiveMQConnection</a> object using the property.</p><structured-macro ac:macro-id="68830b08-1a0d-4d5a-ab6e-78cd6ef9089e" ac:name="code" ac:schema-version="1"><parameter ac:name="">java</parameter><plain-text-body>((ActiveMQConnection)connection).setUseAsyncSend(true);
</plain-text-body></structured-macro><h3>Also see</h3><ul><li><link><page ri:content-title="Connection Configuration URI"></page></link></li><li><link><page ri:content-title="Should I use transactions"></page></link></li><li><link><page ri:content-title="Consumer Dispatch Async"></page></link></li></ul></div>