Question

I've configured spring for jms listener to consume messages from hornetQ as follows.

<bean name="connectionFactory" class="com.kp.jms.KPHornetQJMSConnectionFactory"
    destroy-method="close">
    <constructor-arg name="ha" type="boolean" value="false" />
    <constructor-arg>
        <array>
            <ref bean="transportConfiguration"></ref>
        </array>
    </constructor-arg>
    <property name="maxRetryInterval" value="10000" />
    <property name="reconnectAttempts" value="10" />
    <property name="retryInterval" value="5000" />
    <property name="retryIntervalMultiplier" value="2" />
    <property name="initialConnectAttempts" value="10" />
</bean>

<bean name="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="connectionFactory"></property>
</bean>


<bean name="kpJmsDelegator"
    class="com.kp.KPDelegator">
    <property name="jmsTemplate" ref="jmsTemplate"></property>
</bean>


<jms:listener-container connection-factory="connectionFactory"
    concurrency="1"  >
    <jms:listener destination="kpQueue" ref="kpJmsDelegator"
        method="onMessage" />
</jms:listener-container>

The code works fine when the hornetq server is up and running. However when I start the application and without starting the hornetq I'm getting, could not find queue in warn mode every 5seconds. which I found that the DefaultMessageListenerContainer class sets the default recovery time to 5seconds. However I'm expecting the recovery settings to be considered from connection factory and use recovery attempts to be for 10times and if still could not connect give the reconnect resulting in manual restart of the server if jms to reactivate. Since reattempt is not considered my log is bombarded with error message. I'm not sure where I'm going wrong, could someone point out what is the mistake I'm doing?

Here is the stack trace

014-04-24 18:27:27,159 [org.springframework.jms.listener.DefaultMessageListenerContainer#1-227] WARN  o.s.j.l.DefaultMessageListenerContainer - Setup of JMS message listener invoker failed for destination 'snmpQueue' - trying to recover. Cause: There is no queue with name kpQueue
javax.jms.JMSException: There is no queue with name snmpQueue
    at org.hornetq.jms.client.HornetQSession.createQueue(HornetQSession.java:407) ~[hornetq-jms-2.2.21.Final.jar:2.2.21.SNAPSHOT (HQ_2_2_21_final, 122)]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveQueue(DynamicDestinationResolver.java:101) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveDestinationName(DynamicDestinationResolver.java:66) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:100) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:221) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1119) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1095) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1088) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:985) ~[spring-jms-3.2.3.RELEASE.jar:3.2.3.RELEASE]
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_32]
Was it helpful?

Solution

However I'm expecting the recovery settings to be considered from connection factory and use recovery attempts to be for 10times

Both attributes are not part of the ConnectionFactory contract so there is no way for DefaultMessageListenerContainer to figure that out.

You can rewrite your config as follows to use a 10 sec recovery interval:

<jms:listener-container connection-factory="connectionFactory"
                        concurrency="1" recovery-interval="10000">
    <jms:listener destination="kpQueue" ref="kpJmsDelegator"
                  method="onMessage" />
</jms:listener-container>

There is no way to limit the number of recoveries but it should be fairly easy for you to extend from DefaultMessageListenerContainer and create your own extension of recoverAfterListenerSetupFailure. You could retry a number of times and if that's not working, you could call stop on the container to stop listening on that queue. That means that if the broker is failing and resume after 20 min or so, your listener won't be enabled anymore...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top