How to set the ActiveMQ redeliveryPolicy on a queue?

edbras picture edbras · Mar 17, 2011 · Viewed 22.5k times · Source

How do I set the redeliveryPolicy in ActiveMQ on a Queue?

1) In the doc, see: activeMQ Redelivery, the explain that you should set it on the ConnectionFactory or Connection. But I want to use different value's for different Queue's.

2) Apart from that, I don't seem to get it work. Setting it on the connection factory in Spring (I am using activemq 5.4.2. with Spring 3.0) like this don't seem to have any effect:

<amq:connectionFactory id="amqConnectionFactory" brokerURL="${jms.factory.url}" >
    <amq:properties>
        <amq:redeliveryPolicy maximumRedeliveries="6" initialRedeliveryDelay="15000" useExponentialBackOff="true" backOffMultiplier="5"/>
    </amq:properties>
</amq:connectionFactory>

I also tried to set it as property on the defined Queue, but that also seem to be ignored as the redelivery occurs sooner that the defined values:

<amq:queue id="jmsQueueDeclarationSnd"  physicalName="${jms.queue.declaration.snd}" >
    <amq:properties>
        <amq:redeliveryPolicy maximumRedeliveries="6" initialRedeliveryDelay="15000" useExponentialBackOff="true" backOffMultiplier="5"/>
    </amq:properties>
</amq:queue>

Thanks

Answer

Wayne Earnshaw picture Wayne Earnshaw · Oct 29, 2012

I too was using the method shown by Ivan above for amq:connectionFactory

Whilst upgrading to ActiveMQ 5.7.0 I noticed this no longer works (since the implementation of https://issues.apache.org/jira/browse/AMQ-3224). Anyway after reading a better post on the ActiveMQ forums I currently use :-

<amq:queue id="emailQueue" physicalName="emailQueue" />
<amq:queue id="smsQueue" physicalName="smsQueue" />

<!-- Wait 15 seconds first re-delivery, then 45, 135, 405, 1215, 3645 seconds -->
<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
    <property name="backOffMultiplier" value="3" />
    <property name="initialRedeliveryDelay" value="15000" />
    <property name="maximumRedeliveries" value="6" />
    <property name="queue" value="*" />
    <property name="redeliveryDelay" value="15000" />
    <property name="useExponentialBackOff" value="true" />
</bean>

<amq:connectionFactory id="jmsFactory" brokerURL="yourProtocol/BrokerURL">
    <property name="redeliveryPolicy" ref="redeliveryPolicy" />
</amq:connectionFactory>

Note that for any messages that fail to be redelivered after 6 retries, ActiveMQ will create a DLQ.emailQueue' or DLQ.smsQueue and enqueue the message on that queue (dequeuing it from the original queue).