ActiveMQ和CachingConnectionFactory的自动重新连接问题 [英] Autoreconnect problem with ActiveMQ and CachingConnectionFactory

查看:261
本文介绍了ActiveMQ和CachingConnectionFactory的自动重新连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用ActiveMQ和Spring的 CachingConnectionFactory 时遇到问题。我是这样设置它们的:

I'm having a problem with ActiveMQ and Spring's CachingConnectionFactory. I'm setting them up like this:

<!-- A connection to ActiveMQ --> 
<bean id="myConnectionFactory" 
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${jms.url}"/>
    <property name="userName" value="${jms.username}"/>
    <property name="password" value="${jms.password}"/>
</bean>

<!-- A cached connection to wrap the ActiveMQ connection --> 
<bean id="myCachedConnectionFactory" 
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="myConnectionFactory"/>
    <property name="sessionCacheSize" value="10"/>
    <property name="reconnectOnException" value="true"/>
</bean>

<!-- A destination in ActiveMQ --> 
<bean id="myDestination" 
    class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="${jms.queue}" />
</bean>

<!-- A JmsTemplate instance that uses the cached connection and destination --> 
<bean id="myProducerTemplate" 
    class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="myCachedConnectionFactory"/>
    <property name="defaultDestination" ref="myDestination"/>
</bean>

jms.url 正在使用故障转移传输:

jms.url is using the failover transport:

failover:(tcp://firstbox:6166,tcp://secondbox:6166)?timeout=3000

我遇到的问题是,如果一个盒子掉了,我们应该开始在另一个盒子上发送消息,但它似乎仍在使用旧的连接(每次发送超时)。如果我重新启动该程序,它将再次连接并且一切正常。

The problem I'm having is that if one box goes down, we should start sending messages on the other, but it seems to still be using the old connection (every send times out). If I restart the program, it'll connect again and everything works.

我的理解是, ActiveMQConnectionFactory 应该自行修复(重新连接到新框),并且 JmsTemplate 应该每次都请求新的连接,所以应该可以。我想知道 CachingConnectionFactory 是否可能做得不好(正在缓存与旧服务器对话的生产者?)。

My understanding is that the ActiveMQConnectionFactory should fix itself (reconnect to a new box), and the JmsTemplate should be requesting a new connection every time, so that should be ok. I'm wondering if the CachingConnectionFactory might be doing something bad (caching a producer that talks to the old server?).

我在这里错过了我需要做的事情吗?我的设置似乎很正常,但是找不到其他有此问题的人。

Am I missing something I need to do here? My setup seems fairly normal, but I can't find anyone else having this problem.

推荐答案

我遇到的问题是ActiveMQ在重新连接时没有告诉 CachingConnectionFactory ,因此仍在使用缓存的连接。我用ActiveMQ的 PooledConnectionFactory 代替了,问题就消失了。

The problem I was having is that ActiveMQ wasn't telling the CachingConnectionFactory when it reconnected, so the cached connection was still being used. I replaced it with ActiveMQ's PooledConnectionFactory and the problem went away.

这篇关于ActiveMQ和CachingConnectionFactory的自动重新连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆