在 Spring Boot JMS CachingConnectionFactory 中关闭会话
Closing Sessions in Spring Boot JMS CachingConnectionFactory
我的 JMS 配置如下 (Spring boot 1.3.8);
@Configuration
@EnableJms
public class JmsConfig {
@Autowired
private AppProperties properties;
@Bean
TopicConnectionFactory topicConnectionFactory() throws JMSException {
return new TopicConnectionFactory(properties.getBrokerURL(), properties.getBrokerUserName(),
properties.getBrokerPassword());
}
@Bean
CachingConnectionFactory connectionFactory() throws JMSException {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(topicConnectionFactory());
connectionFactory.setSessionCacheSize(50);
return connectionFactory;
}
@Bean
JmsTemplate jmsTemplate() throws JMSException {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
jmsTemplate.setPubSubDomain(Boolean.TRUE);
return jmsTemplate;
}
@Bean
DefaultJmsListenerContainerFactory defaultContainerFactory() throws JMSException {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setPubSubDomain(Boolean.TRUE);
factory.setRecoveryInterval(30 * 1000L);
return factory;
}
}
这应该可以正常工作。但我担心 CachingConnectionFactory
的文档上写了什么
特别是这些部分;
NOTE: This ConnectionFactory requires explicit closing of all Sessions obtained from its shared Connection
Note also that MessageConsumers obtained from a cached Session won't get closed until the Session will eventually be removed from the pool. This may lead to semantic side effects in some cases.
我以为框架处理了关闭会话和连接部分?如果没有;我应该如何正确关闭它们?
或者我遗漏了什么?
感谢任何帮助:)
F.Y.I : 我使用 SonicMQ 作为代理
是的,JmsTemplate
将关闭会话; javadocs指的是直接在框架外使用。
我的 JMS 配置如下 (Spring boot 1.3.8);
@Configuration
@EnableJms
public class JmsConfig {
@Autowired
private AppProperties properties;
@Bean
TopicConnectionFactory topicConnectionFactory() throws JMSException {
return new TopicConnectionFactory(properties.getBrokerURL(), properties.getBrokerUserName(),
properties.getBrokerPassword());
}
@Bean
CachingConnectionFactory connectionFactory() throws JMSException {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(topicConnectionFactory());
connectionFactory.setSessionCacheSize(50);
return connectionFactory;
}
@Bean
JmsTemplate jmsTemplate() throws JMSException {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
jmsTemplate.setPubSubDomain(Boolean.TRUE);
return jmsTemplate;
}
@Bean
DefaultJmsListenerContainerFactory defaultContainerFactory() throws JMSException {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory());
factory.setPubSubDomain(Boolean.TRUE);
factory.setRecoveryInterval(30 * 1000L);
return factory;
}
}
这应该可以正常工作。但我担心 CachingConnectionFactory
的文档上写了什么特别是这些部分;
NOTE: This ConnectionFactory requires explicit closing of all Sessions obtained from its shared Connection
Note also that MessageConsumers obtained from a cached Session won't get closed until the Session will eventually be removed from the pool. This may lead to semantic side effects in some cases.
我以为框架处理了关闭会话和连接部分?如果没有;我应该如何正确关闭它们?
或者我遗漏了什么?
感谢任何帮助:)
F.Y.I : 我使用 SonicMQ 作为代理
是的,JmsTemplate
将关闭会话; javadocs指的是直接在框架外使用。