Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why DefaultMessageListenerContainer should not use CachingConnectionFactory?

Tags:

jms

spring-jms

I was reading spring documentation on DefaultMessageListenerContainer

It says "Note: Don't use Spring's CachingConnectionFactory in combination with dynamic scaling. Ideally, don't use it with a message listener container at all, since it is generally preferable to let the listener container itself handle appropriate caching within its lifecycle. Also, stopping and restarting a listener container will only work with an independent, locally cached Connection - not with an externally cached one."

Could anybody explain why?

like image 857
EmeraldTablet Avatar asked Feb 24 '14 09:02

EmeraldTablet


1 Answers

  1. You really don't need to cache sessions for listener containers because the sessions are long lived; caching is very beneficial for frequent short use, such as with the JmsTemplate.
  2. The problem is really when cacheConsumers = true (the default). When using dynamic scaling and a listener is stopped, the session is returned to the cache but the broker doesn't know that nobody will actually consume from that session, so you are stuck with messages sitting in the cache that won't be read until that session happens to be reused when the volume increases.

Note: if you wish a JmsTemplate running on the container thread to participate in a container transaction, you should use a CachingConnectionFactory so the producers can be cached, but you should disable caching consumers in the factory if you have variable concurrency.

like image 82
Gary Russell Avatar answered Sep 22 '22 08:09

Gary Russell