ActiveMQ 和 CachingConnectionFactory 的自动重新连接问题

发布于 2024-11-05 09:46:00 字数 1790 浏览 2 评论 0原文

我在使用 ActiveMQ 和 Spring 的 CachingConnectionFactory 时遇到问题。我将它们设置如下:

<!-- 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 正在使用故障转移传输:

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

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

我的理解是 ActiveMQConnectionFactory 应该修复自身(重新连接到新盒子),而 JmsTemplate 应该每次都请求新连接,所以应该没问题。我想知道 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 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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情仇皆在手 2024-11-12 09:46:00

我遇到的问题是 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.

木有鱼丸 2024-11-12 09:46:00

仅供参考,我刚刚测试了两个本地 AMQ 代理之间的这种场景(使用 CachingConnectionFactory 进行生产者/消费者连接),并且故障转移工作正常...

也就是说...在使用轮询消费者模式时,我看到了其他消费者连接问题...必须需要手动关闭连接什么的。

FYI, I just tested this scenario (using CachingConnectionFactory for both producer/consumer connections) between two local AMQ brokers and the failover worked fine...

that being said...I'm seeing other Consumer connection issues when using a polling consumer pattern...must need to manually close connections or something.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文