Question

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

Was it helpful?

Solution 2

I got it working by setting it on the factory as done above but only when creating the connection factory as a Spring bean and not through XBean as shown above. This is because the xsd doesn't allow you to set the redeliveryPolicy as an object, but merely as a String. After setting the cache level to Consumer in Spring's DefaultMessageListenerContainer, it all worked.

On the queue , it seems that you simple can set a delivery policy... Strange, as I would like to have different settings for different queue's/topics. Just imagine you have a slow and faster queue, or a external system that you connect to that needs more time to recover.. Maybe this feature is still to be implemented

OTHER TIPS

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).

You can set the redeliveryPolicy within the amq namespace like this:

<amq:connectionFactory id="jmsRedeliverConnectionFactory" brokerURL="vm://localhost">
  <amq:redeliveryPolicy>
    <amq:redeliveryPolicy maximumRedeliveries="5" initialRedeliveryDelay="1000" useExponentialBackOff="true" backOffMultiplier="5" />
  </amq:redeliveryPolicy>
</amq:connectionFactory>

I could not get ActiveMQ (5.7.0) to recognize my redelivery policy when I defined it using <amq:properties> on the ConnectionFactory or the Queue (it kept using the default redelivery policy). What worked for me is this:

  • Create the RedeliveryPolicy as a standalone bean, then Spring-reference it in the ConnectionFactory
  • Create an explicit DLQ and Spring-reference it in the RedeliveryPolicy

Spring config as follows:

<amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost" redeliveryPolicy="#activeMQRedeliveryPolicy" />

<amq:redeliveryPolicy id="activeMQRedeliveryPolicy" destination="#myDLQ" useExponentialBackOff="true" backOffMultiplier="3" maximumRedeliveries="4" />

<amq:queue id="myDLQ" physicalName="DLQ.myDLQ" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top