即使使用 PooledConnectionFactory,JmsTemplate 也不会关闭连接
我们使用 AMQ Broker 5.5 和 Spring 3.0 来配置连接工厂和其他东西。 我们使用的连接工厂是 PooledConnectionFactory,我的配置的一部分如下所示:
<属性名称=“connectionFactory”>
<属性名称=“explicitQosEnabled”值=“true”/>
<属性名称=“timeToLive”值=“86400000”/>
几天前,我们的代理崩溃并不断重新启动,并出现以下错误:
java.lang.OutOfMemoryError: requests
369384 bytes for Chunk::new。交换空间不足?
那时,从 jconsole 中,我找不到代理的任何异常情况,除了我们的一个客户端应用程序 它通过每分钟发送和侦听消息来与服务器进行通信(通过代理),创建了约 3000 个连接(在 jconsole 上看到)。 一旦我们关闭它,一切就恢复正常了。
因此,为了避免这种情况,我尝试在finally块中关闭连接,执行类似的操作。
try {
connection = myJmsTemplate.getConnectionFactory().createConnection();
session = connection.createSession(false, 1);
String messageSelector = "JMSCorrelationID='" + correlationId + "'";
responseConsumer = session.createConsumer(receiveDestination, messageSelector);
LOG.info("Starting connection");
connection.start();
myJmsTemplate.send(sendDestination, new SimpleTextMessageCreator(
message, receiveDestination, correlationId));
LOG.info("Waiting for message with " + messageSelector + " for " + DEFAULT_TIMEOUT + " ms");
TextMessage responseMessage = (TextMessage) responseConsumer.receive(DEFAULT_TIMEOUT);
}
catch (Someexception e) {do something}
finally {
responseConsumer.close();
session.close();
connection.close();
}
但即便如此,我也可以看到连接在 jconsole 中浮动,并且只有在发布消息的客户端应用程序关闭时才会丢失。 有人可以帮助我了解这里发生的情况以及如何在每个 pub sub 周期后关闭连接。
提前谢谢你,
哈里
We use AMQ broker 5.5 and Spring 3.0 for configuring connection factory and other stuffs.
The connection factory we are using is PooledConnectionFactory and a part of my config looks like this:
<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="some_url"/>
</bean>
</property>
</bean>
<!-- Spring JMS Template -->
<bean id="jmsTemplate"
class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref local="jmsFactory" />
</property>
<property name="explicitQosEnabled" value="true"/>
<property name="timeToLive" value="86400000"/>
</bean
A few days back our broker crashed and kept restarting with this error:
java.lang.OutOfMemoryError: requested
369384 bytes for Chunk::new. Out of swap space?
At that point of time, from jconsole, I could not find anything unusual with the broker, except that one of our client application
which talks with the server (via broker) by sending and listening to messages every minute had created ~3000 connections (saw it on jconsole).
Once we had shut it down, everything was back to normal.
So, to avoid this I tried closing the connection in finally block doing something like this.
try {
connection = myJmsTemplate.getConnectionFactory().createConnection();
session = connection.createSession(false, 1);
String messageSelector = "JMSCorrelationID='" + correlationId + "'";
responseConsumer = session.createConsumer(receiveDestination, messageSelector);
LOG.info("Starting connection");
connection.start();
myJmsTemplate.send(sendDestination, new SimpleTextMessageCreator(
message, receiveDestination, correlationId));
LOG.info("Waiting for message with " + messageSelector + " for " + DEFAULT_TIMEOUT + " ms");
TextMessage responseMessage = (TextMessage) responseConsumer.receive(DEFAULT_TIMEOUT);
}
catch (Someexception e) {do something}
finally {
responseConsumer.close();
session.close();
connection.close();
}
But even then I can see the connections floating around in jconsole and are only lost if the client app which publishes the messages is brought down.
Can someone please help me understand what's happening here and how I can close the connections after each pub sub cycle.
Thank you in advance,
Hari
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虚惊。还有另一段代码使连接保持打开状态。关闭它解决了这个问题。
False alarm. There was another piece of code that was leaving the connection open. Closing it solved the issue.