0

I have my JMS configuration like below (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;
    }
}

This should work fine. But i am worried about whats written on the doc of CachingConnectionFactory

Specially, these parts;

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.

I thought the framework handled the closing session and connection part? If it does not; how should i close them properly?

or maybe i am missing something?

Any help is appreciated :)

F.Y.I : I Use SonicMQ as the broker

Community
  • 1
  • 1
Rajkishan Swami
  • 3,569
  • 10
  • 48
  • 68

1 Answers1

2

Yes, the JmsTemplate will close the session; the javadocs refer to direct use outside of the framework.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • What do you mean by direct use outside the framework ? – Diego Ramos Dec 02 '19 at 19:03
  • I mean that framework components (`JmsTemplate`, listener containers) will reliably close the sessions when appropriate. If you create your own sessions directly on the shared connection, you are responsible for closing them. – Gary Russell Dec 02 '19 at 19:12