springspring-jms

Prevent use of CachingConnectionFactory with DefaultJmsListenerContainerFactory


I am working on a brand new project in which I need to have listeners that will consume messages from several queues (no need to have producer for now).

Starting from scratch, I am using the last Spring JMS version (4.1.2).

Here is an extract of my configuration file:

<bean id="cachedConnectionFactory" 
          class="org.springframework.jms.connection.CachingConnectionFactory"
        p:targetConnectionFactory-ref="jmsConnectionFactory"
        p:sessionCacheSize="3" />

<bean id="jmsListenerContainerFactory"
          class="org.springframework.jms.config.DefaultJmsListenerContainerFactory"
          p:connectionFactory-ref="cachedConnectionFactory"
          p:destinationResolver-ref="jndiDestinationResolver"
          p:concurrency="3-5"
          p:receiveTimeout="5000" />

But I think I may be wrong since DefaultJmsListenerContainerFactory will build regular DefaultMessageListenerContainerS. And, as stated in the doc, CachingConnectionFactory should not be used with a message listener container...

Thanks for any tips


Solution

  • As stated in the answer you cited, it's ok to use a CCF as long as you disable consumer caching.

    Correction: Yes, when using the SingleConnectionFactory, you do need to set reconnectOnException to true in order for the container to properly recover its connection. Otherwise, it simply hands out the stale connection.