The java doc here related to Spring CachingConnectionFactory has comment :
NOTE: This ConnectionFactory requires explicit closing of all Sessions obtained from its shared Connection. This is the usual recommendation for native JMS access code anyway. However, with this ConnectionFactory, its use is mandatory in order to actually allow for Session reuse.
I am not clear how to handle this with the below given configuration in my application.
<bean id="springApp" class="com.codereq.springcore.jms.SpringJMSListenerApp" />
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="destination" ref="destination"/>
<property name="messageListener" ref="messageListener"/>
<property name="sessionTransacted" value="true"/>
<property name="concurrentConsumers" value="5" />
<property name="maxConcurrentConsumers" value="15" />
</bean>
<bean id="messageListener" class="com.codereq.springcore.jms.MessageListenerApp" />
<bean id="jmsConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"
p:targetConnectionFactory-ref="emsConnectionFactory"
p:sessionCacheSize="100"
p:cacheConsumers="true" />
<bean id="emsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="GenericConnectionFactory"/>
<property name="jndiTemplate" ref="jndiTemplate"/>
</bean>
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">com.tibco.tibjms.naming.TibjmsInitialContextFactory</prop>
<prop key="java.naming.provider.url">tibjmsnaming://localhost:7222</prop>
<prop key="java.naming.security.principal">admin</prop>
<prop key="java.naming.security.credentials">admin</prop>
</props>
</property>
</bean>
<bean id="destination" class="com.tibco.tibjms.TibjmsQueue">
<constructor-arg value="com.sample.queue" />
</bean>
The listener class is this :
public class MessageListenerApp implements MessageListener {
private static int c = 0;
@Override
public void onMessage(Message arg0) {
try {
System.out.println("Received Message..."+arg0.getStringProperty("MessageNum")+". Waiting to finish..");
Thread.sleep(2000);
System.out.println("Finished processing.."+arg0.getStringProperty("MessageNum")+".."+(c++));
} catch (Exception e) {
e.printStackTrace();
}
}
}
How do I follow recommendation that Sessions obtained from shared connection should be closed explicitly ?
Came across SessionAwareMessageListener interface which provides onMessage method which gives handle to Session. So to properly implement session closing, should this interface be implemented ?