HornetQ重新连接——不使用DefaultMessageListenerContainer。

时间:2020-12-05 20:51:28

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

我已经为jms侦听器配置了spring,用于从hornetQ中获取消息,如下所示。

<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?

当hornetq服务器启动并运行时,代码运行良好。然而,当我启动应用程序时,如果没有启动hornetq,就不能每5秒就在警告模式中找到队列。我发现DefaultMessageListenerContainer类将默认恢复时间设置为5秒。但是,我希望从连接工厂中考虑恢复设置,并使用恢复尝试10次,如果仍然不能连接,则重新连接,如果jms重新激活,将导致服务器重新启动。因为重新尝试没有被认为是我的日志被错误信息轰炸。我不确定我哪里出错了,有人能指出我所犯的错误吗?

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]

1 个解决方案

#1


2  

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

但是,我希望从连接工厂考虑恢复设置,并使用恢复尝试10次。

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

这两个属性都不是ConnectionFactory合同的一部分,所以DefaultMessageListenerContainer没有办法解决这个问题。

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

您可以重新编写您的配置,如下所示,使用10秒的恢复间隔:

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

没有办法限制恢复的数量,但是您可以很容易地从DefaultMessageListenerContainer扩展,并创建自己的恢复后的恢复(listenersetupfailure)。您可以重试几次,如果这不起作用,您可以调用stop在容器上停止侦听该队列。这意味着,如果代理在20分钟左右失败并恢复,您的侦听器将不再启用……

#1


2  

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

但是,我希望从连接工厂考虑恢复设置,并使用恢复尝试10次。

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

这两个属性都不是ConnectionFactory合同的一部分,所以DefaultMessageListenerContainer没有办法解决这个问题。

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

您可以重新编写您的配置,如下所示,使用10秒的恢复间隔:

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

没有办法限制恢复的数量,但是您可以很容易地从DefaultMessageListenerContainer扩展,并创建自己的恢复后的恢复(listenersetupfailure)。您可以重试几次,如果这不起作用,您可以调用stop在容器上停止侦听该队列。这意味着,如果代理在20分钟左右失败并恢复,您的侦听器将不再启用……