How to set the ActiveMQ redeliveryPolicy on a queue?
Asked Answered
M

4

15

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

Mahmud answered 16/3, 2011 at 23:33 Comment(1)
Can you post the working configuration?Forty
M
6

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

Mahmud answered 17/3, 2011 at 13:13 Comment(2)
Since the redelivery policy is not specific to a destination, you would need to define multiple connections with different redelivery policies and then use different connections to access different destinations. This is pretty easy to do if you control which connections are utilized by which consumers, e.g., in a Spring config. If clients are looking up their own connection, say, via JNDI, then you will need to be more meticulous about how you name different connections and which connections you advise clients to use.Tbilisi
As of ActiveMQ v5.7.0 you can now configure a RedeliveryPolicy on a per-destination basis.Calista
C
8

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

Cookshop answered 29/10, 2012 at 4:58 Comment(2)
So does this mean that DLQ.emailQueue is where the message will be placed when max retries has been reached? I can't find any documentation on what exactly destination is.Shannashannah
sure, there is a new queue 'DLQ.emailQueue' created the first time max retries is reached and the message moves from 'emailQueue' to that one. I see them with destination = 'queue://DLQ.emailQueue', redelivered = 'false' in this case since it failed.Cookshop
M
6

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

Mahmud answered 17/3, 2011 at 13:13 Comment(2)
Since the redelivery policy is not specific to a destination, you would need to define multiple connections with different redelivery policies and then use different connections to access different destinations. This is pretty easy to do if you control which connections are utilized by which consumers, e.g., in a Spring config. If clients are looking up their own connection, say, via JNDI, then you will need to be more meticulous about how you name different connections and which connections you advise clients to use.Tbilisi
As of ActiveMQ v5.7.0 you can now configure a RedeliveryPolicy on a per-destination basis.Calista
A
3

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>
Arrogant answered 16/5, 2012 at 9:50 Comment(0)
T
2

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" />
Tinderbox answered 30/1, 2013 at 19:36 Comment(1)
The redelivery works for me but the DLQ don't, still posting at activemq.DLQDiskin

© 2022 - 2024 — McMap. All rights reserved.