We configure our JMS destinations via JNDI lookup as follows:
@Bean
JndiObjectFactoryBean myTopic(@Value("${topic}") String topic,
JndiTemplate jndiTemplate) {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate);
jndiObjectFactoryBean.setJndiName(topic);
return jndiObjectFactoryBean;
}
On initialisation of this bean, Spring confirms the object exists and caches it for use later. Does the caching of this Destination involve a persistent connection being created to our broker as well? Or is the connection only physically created when our CachingConnectionFactory is instantiated?
The (only and shared) connection is created when you call createConnection()
for the 1st time on your CachingConnectionFactory
instance and released on the call to destroy()
or resetConnection()
as stated per the contract (CachingConnectionFactory
inherit from SingleConnectionFactory
) :
A JMS ConnectionFactory adapter that returns the same Connection from all createConnection() calls, and ignores calls to Connection.close()