blob: 26d774f1c64a68067d52b32591b4eafc2125b712 [file] [log] [blame]
<div class="wiki-content maincontent"><h2>Redelivery Policy</h2><p>Detail on when messages are redelivered to a client can be found in the <link><page ri:content-title="Message Redelivery and DLQ Handling"></page></link> section. You can configure the <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java?view=markup">RedeliveryPolicy</a> on your <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java?view=markup">ActiveMQConnectionFactory</a> or <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java?view=markup">ActiveMQConnection</a> to customize exactly how you want the redelivery to work.</p><p>You can use Java code, Spring or the <link><page ri:content-title="Connection Configuration URI"></page></link> to customize this.</p><h3>Available Properties</h3><table><tbody><tr><th colspan="1" rowspan="1"><p>Property</p></th><th colspan="1" rowspan="1"><p>Default Value</p></th><th colspan="1" rowspan="1"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1"><p><code>backOffMultiplier</code></p></td><td colspan="1" rowspan="1"><p><code>5</code></p></td><td colspan="1" rowspan="1"><p>The back-off multiplier.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>collisionAvoidanceFactor</code></p></td><td colspan="1" rowspan="1"><p><code>0.15</code></p></td><td colspan="1" rowspan="1"><p>The percentage of range of collision avoidance if enabled.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>initialRedeliveryDelay</code></p></td><td colspan="1" rowspan="1"><p><code>1000L</code></p></td><td colspan="1" rowspan="1"><p>The initial redelivery delay in milliseconds.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>maximumRedeliveries</code></p></td><td colspan="1" rowspan="1"><p><code>6</code></p></td><td colspan="1" rowspan="1"><p>Sets the maximum number of times a message will be redelivered before it is considered a <strong>poisoned pill</strong> and returned to the broker so it can go to a Dead Letter Queue.</p><p>Set to <strong><code>-1</code></strong> for unlimited redeliveries.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>maximumRedeliveryDelay</code></p></td><td colspan="1" rowspan="1"><p><code>-1</code></p></td><td colspan="1" rowspan="1"><p>Sets the maximum delivery delay that will be applied if the&#160;<strong><code>useExponentialBackOff</code></strong> option is set. (use value&#160;<strong><code>-1</code></strong> to define that no maximum be applied) (<span style="color: red;">v5.5</span>).</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>redeliveryDelay</code></p></td><td colspan="1" rowspan="1"><p><code>1000L</code></p></td><td colspan="1" rowspan="1"><p>The delivery delay if&#160;<strong><code>initialRedeliveryDelay=0</code></strong> (<span style="color: red;">v5.4</span>).</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>useCollisionAvoidance</code></p></td><td colspan="1" rowspan="1"><p><code>false</code></p></td><td colspan="1" rowspan="1"><p>Should the redelivery policy use collision avoidance.</p></td></tr><tr><td colspan="1" rowspan="1"><p><code>useExponentialBackOff</code></p></td><td colspan="1" rowspan="1"><p><code>false</code></p></td><td colspan="1" rowspan="1"><p>Should exponential back-off be used, i.e., to exponentially increase the timeout.</p></td></tr></tbody></table><h2>RedeliveryPolicy per Destination</h2><p>As of ActiveMQ v5.7.0 you can now configure a <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java?view=markup">RedeliveryPolicy</a> on a per-destination bases. The&#160;<strong><code>ActiveMQConnection</code></strong> factory class now exposes a <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/broker/region/policy/RedeliveryPolicyMap.java?view=markup">RedeliveryPolicyMap</a> property that allows to assign a RedeliveryPolicy using named destinations or using destination wildcards. The code snipped below shows how to configure a different <a shape="rect" href="http://svn.apache.org/viewvc/activemq/trunk/activemq-client/src/main/java/org/apache/activemq/RedeliveryPolicy.java?view=markup">RedeliveryPolicy</a> for Topics and Queues.</p><structured-macro ac:macro-id="7d31d1f3-c21c-4223-9684-c746160b6941" ac:name="code" ac:schema-version="1"><plain-text-body> ActiveMQConnection connection ... // Create a connection
RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
queuePolicy.setInitialRedeliveryDelay(0);
queuePolicy.setRedeliveryDelay(1000);
queuePolicy.setUseExponentialBackOff(false);
queuePolicy.setMaximumRedeliveries(2);
RedeliveryPolicy topicPolicy = new RedeliveryPolicy();
topicPolicy.setInitialRedeliveryDelay(0);
topicPolicy.setRedeliveryDelay(1000);
topicPolicy.setUseExponentialBackOff(false);
topicPolicy.setMaximumRedeliveries(3);
// Receive a message with the JMS API
RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap();
map.put(new ActiveMQTopic("&gt;"), topicPolicy);
map.put(new ActiveMQQueue("&gt;"), queuePolicy);
</plain-text-body></structured-macro></div>