From 61f89a1f049dd69b8b8b356168888fa5aae17a71 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 3 Sep 2023 01:13:51 +0200 Subject: [PATCH] Refine note on listener container setup with CachingConnectionFactory Closes gh-25503 --- .../listener/DefaultMessageListenerContainer.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java index 4c700feffaa9..af2a2993db3d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java @@ -98,12 +98,14 @@ * number of 1 consumer, otherwise you'd receive the same message multiple times on * the same node. * - *

Note: Don't use Spring's {@link org.springframework.jms.connection.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. + *

Note: You may use {@link org.springframework.jms.connection.CachingConnectionFactory} + * with a listener container but it comes with limitations. 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 {@code Connection}, not with an externally cached one. Last but not least, + * with {@code CachingConnectionFactory}, dynamic scaling with custom provider hints such as + * {@link #setMaxMessagesPerTask "maxMessagesPerTask"} can result in JMS messages delivered + * to cached consumers even when they are no longer attached to the listener container. * *

It is strongly recommended to either set {@link #setSessionTransacted * "sessionTransacted"} to "true" or specify an external {@link #setTransactionManager