layout: default_md title: Redelivery Policy title-class: page-title-activemq5 type: activemq5

Features > Consumer Features > Redelivery Policy

Redelivery Policy

Detail on when messages are redelivered to a client can be found in the Message Redelivery and DLQ Handling section. You can configure the RedeliveryPolicy on your ActiveMQConnectionFactory or ActiveMQConnection to customize exactly how you want the redelivery to work.

You can use Java code, Spring or the Connection Configuration URI to customize this.

Available Properties

PropertyDefault ValueDescription
backOffMultiplier5The back-off multiplier.
collisionAvoidanceFactor0.15The percentage of range of collision avoidance if enabled.
initialRedeliveryDelay1000LThe initial redelivery delay in milliseconds.
maximumRedeliveries6Sets the maximum number of times a message will be redelivered before it is considered a poisoned pill and returned to the broker so it can go to a Dead Letter Queue. Set to -1 for unlimited redeliveries.
maximumRedeliveryDelay-1Sets the maximum delivery delay that will be applied if the useExponentialBackOff option is set. (use value -1 to define that no maximum be applied) (v5.5).
redeliveryDelay1000LThe delivery delay if initialRedeliveryDelay=0 (v5.4).
useCollisionAvoidancefalseShould the redelivery policy use collision avoidance.
useExponentialBackOfffalseShould exponential back-off be used, i.e., to exponentially increase the timeout.

RedeliveryPolicy per Destination

As of ActiveMQ v5.7.0 you can now configure a RedeliveryPolicy on a per-destination bases. The ActiveMQConnection factory class now exposes a RedeliveryPolicyMap property that allows to assign a RedeliveryPolicy using named destinations or using destination wildcards. The code snipped below shows how to configure a different RedeliveryPolicy for Topics and Queues.

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(">"), topicPolicy);
map.put(new ActiveMQQueue(">"), queuePolicy);