@@ -1971,6 +1971,13 @@ the message getting redelivered. Alternatively, consider using 'CLIENT_ACKNOWLED
1971
1971
which provides redelivery in case of an exception as well but does not use transacted
1972
1972
Sessions and therefore does not include any other Session operations (such as sending
1973
1973
response messages) in the transaction protocol.
1974
+
1975
+ **The default 'AUTO_ACKNOWLEDGE' mode does not provide proper reliability guarantees.**
1976
+ Messages may get lost when listener execution fails (since the provider will automatically
1977
+ acknowledge each message after listener invocation, with no exceptions to be propagated to
1978
+ the provider) or when the listener container shuts down (this may be configured through
1979
+ the 'acceptMessagesWhileStopping' flag). Make sure to use transacted sessions in case of
1980
+ reliability needs, e.g. for reliable queue handling and durable topic subscriptions.
1974
1981
====
1975
1982
1976
1983
[[jms-mdp-default]]
@@ -2008,6 +2015,13 @@ alternative: wrapping your entire processing with an XA transaction (through con
2008
2015
your `DefaultMessageListenerContainer` with an `JtaTransactionManager`), covering the
2009
2016
reception of the JMS message as well as the execution of the business logic in your
2010
2017
message listener (including database operations etc).
2018
+
2019
+ **The default 'AUTO_ACKNOWLEDGE' mode does not provide proper reliability guarantees.**
2020
+ Messages may get lost when listener execution fails (since the provider will automatically
2021
+ acknowledge each message before listener invocation) or when the listener container shuts
2022
+ down (this may be configured through the 'acceptMessagesWhileStopping' flag). Make sure
2023
+ to use transacted sessions in case of reliability needs, e.g. for reliable queue handling
2024
+ and durable topic subscriptions.
2011
2025
====
2012
2026
2013
2027
@@ -2238,7 +2252,6 @@ Below is a simple implementation of an MDP:
2238
2252
throw new IllegalArgumentException("Message must be of type TextMessage");
2239
2253
}
2240
2254
}
2241
-
2242
2255
}
2243
2256
----
2244
2257
@@ -2281,7 +2294,6 @@ handling method with access to the JMS `Session` from which the `Message` was re
2281
2294
public interface SessionAwareMessageListener {
2282
2295
2283
2296
void onMessage(Message message, Session session) throws JMSException;
2284
-
2285
2297
}
2286
2298
----
2287
2299
@@ -2326,7 +2338,6 @@ various `Message` types that they can receive and handle.
2326
2338
void handleMessage(byte[] message);
2327
2339
2328
2340
void handleMessage(Serializable message);
2329
-
2330
2341
}
2331
2342
----
2332
2343
@@ -2373,7 +2384,6 @@ also how the `'receive(..)'` method is strongly typed to receive and respond onl
2373
2384
public interface TextMessageDelegate {
2374
2385
2375
2386
void receive(TextMessage message);
2376
-
2377
2387
}
2378
2388
----
2379
2389
@@ -2415,7 +2425,6 @@ non-void value. Consider the interface and class:
2415
2425
2416
2426
// notice the return type...
2417
2427
String receive(TextMessage message);
2418
-
2419
2428
}
2420
2429
----
2421
2430
@@ -2642,10 +2651,10 @@ your `@Configuration` classes.
2642
2651
2643
2652
@Bean
2644
2653
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
2645
- DefaultJmsListenerContainerFactory factory =
2646
- new DefaultJmsListenerContainerFactory();
2654
+ DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
2647
2655
factory.setConnectionFactory(connectionFactory());
2648
2656
factory.setDestinationResolver(destinationResolver());
2657
+ factory.setSessionTransacted(true);
2649
2658
factory.setConcurrency("3-10");
2650
2659
return factory;
2651
2660
}
@@ -2674,6 +2683,7 @@ element.
2674
2683
class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
2675
2684
<property name="connectionFactory" ref="connectionFactory"/>
2676
2685
<property name="destinationResolver" ref="destinationResolver"/>
2686
+ <property name="sessionTransacted" value="true"/>
2677
2687
<property name="concurrency" value="3-10"/>
2678
2688
</bean>
2679
2689
----
0 commit comments