Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring JMS - Exponential message re-delivery policy is ignored

We're trying to set a re-delivery policy for ActiveMQ using spring jms. We've set an exponential back-off for the re-deliveries, but it seems to be ignored - the intervals between the message re-deliveries are fixed instead of exponentially growing.

Does anyone know what might be the problem? This is our spring-jms configuration:

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
    p:brokerURL="${activemq_url}">
    <property name="redeliveryPolicy" ref="redeliveryPolicy" />
</bean>

<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
    <property name="queue" value="*" />
    <property name="initialRedeliveryDelay" value="10000" />
    <property name="redeliveryDelay" value="10000" />
    <property name="maximumRedeliveries" value="-1" />
    <property name="useExponentialBackOff" value="true" />
    <property name="backOffMultiplier" value="5" />
</bean>

<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory" 
    p:targetConnectionFactory-ref="connectionFactory" p:sessionCacheSize="10" 
    />

<!-- A JmsTemplate instance that uses the cached connection and destination -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="cachingConnectionFactory" />
    <property name="messageConverter" ref="messageConverter" />
    <property name="sessionTransacted" value="true" />
</bean>

<!-- The Spring message listener container configuration -->
<jms:listener-container container-type="default"
    destination-type="queue" connection-factory="connectionFactory"
    acknowledge="transacted" concurrency="1" cache="consumer">
    <jms:listener destination="testQueue" ref="testService"
        method="onMessage" />
</jms:listener-container>

Thanks!

EDIT: This is a log example, the re-deliveries happen every 5 seconds:

11 May 2014 18:52:00  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:00 IDT 2014
at ...
11 May 2014 18:52:05  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:05 IDT 2014
at ...
11 May 2014 18:52:10  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:10 IDT 2014
at ...
11 May 2014 18:52:15  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:15 IDT 2014
at ...
11 May 2014 18:52:20  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:20 IDT 2014
at ...
like image 924
Ayelet Avatar asked May 11 '14 14:05

Ayelet


1 Answers

So, I think I found the problem: When I was testing the policy before, I threw JMSException to get the messages to be re-delivered.

One I changed the exception that was thrown to Exception/RuntimeException, the exponential back off worked.

I'm not sure why JMSException causes the exponential back off policy to be ignored...Does anyone have any ideas?

like image 105
Ayelet Avatar answered Oct 18 '22 01:10

Ayelet