Amey Jadiye
Amey Jadiye

Reputation: 3154

Which is better to use CachingConnectionFactory or caching in DefaultMessageListenerContainer?

When using the spring-jms, there are 2 options given by spring for connection and session caching for performance gain.

  1. Use the CachingConnectionFactory and cache the sessions, optionally you can cache producer and consumers as well.
  2. Using the DefaultMessageListenerContainer you can set the cacheLevel to [1:connection caching, 2:session caching], with 3 you can cache consumers as well.

My questions Is , why did spring created the redundant functionality ? which one is optimal and fast in terms of performance?

Upvotes: 2

Views: 2253

Answers (1)

Gary Russell
Gary Russell

Reputation: 174494

The caching factory is designed for short-lived sessions such as operations performed with a JmsTemplate.

It's generally not needed with the listener container (because its sessions are generally long-lived), unless you perform JmsTemplate operations on the container's thread - to participate in the container's transaction.

In that case, consumers should not be cached by the factory, especially if variable concurrency is in use. See the container javadocs.

Upvotes: 4

Related Questions