blob: 7d236018537e2ba24350d97e365b0de6e03ab2de [file] [log] [blame]
<div class="wiki-content maincontent"><h2 id="RedeliveryPolicy-RedeliveryPolicy">Redelivery Policy</h2><p>Detail on when messages are redelivered to a client can be found in the <a shape="rect" href="message-redelivery-and-dlq-handling.xml">Message Redelivery and DLQ Handling</a> section. You can configure the <a shape="rect" class="external-link" 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" class="external-link" 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" class="external-link" 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 <a shape="rect" href="connection-configuration-uri.xml">Connection Configuration URI</a> to customize this.</p><h3 id="RedeliveryPolicy-AvailableProperties">Available Properties</h3><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default Value</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>backOffMultiplier</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>5</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The back-off multiplier.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>collisionAvoidanceFactor</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>0.15</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The percentage of range of collision avoidance if enabled.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>initialRedeliveryDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000L</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The initial redelivery delay in milliseconds.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>maximumRedeliveries</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>6</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><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" class="confluenceTd"><p><code>maximumRedeliveryDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>-1</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><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" class="confluenceTd"><p><code>redeliveryDelay</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>1000L</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><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" class="confluenceTd"><p><code>useCollisionAvoidance</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Should the redelivery policy use collision avoidance.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>useExponentialBackOff</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Should exponential back-off be used, i.e., to exponentially increase the timeout.</p></td></tr></tbody></table></div><h2 id="RedeliveryPolicy-RedeliveryPolicyperDestination">RedeliveryPolicy per Destination</h2><p>As of ActiveMQ v5.7.0 you can now configure a <a shape="rect" class="external-link" 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" class="external-link" 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" class="external-link" 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><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ 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(&quot;&gt;&quot;), topicPolicy);
map.put(new ActiveMQQueue(&quot;&gt;&quot;), queuePolicy);
]]></script>
</div></div></div>