1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -152,7 +152,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
152
152
implements MessageListenerContainer {
153
153
154
154
private static final boolean micrometerJakartaPresent = ClassUtils .isPresent (
155
- "io.micrometer.jakarta9.instrument.jms.JmsInstrumentation" , AbstractMessageListenerContainer .class .getClassLoader ());
155
+ "io.micrometer.jakarta9.instrument.jms.JmsInstrumentation" ,
156
+ AbstractMessageListenerContainer .class .getClassLoader ());
156
157
157
158
private volatile @ Nullable Object destination ;
158
159
@@ -166,12 +167,12 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
166
167
167
168
private @ Nullable String subscriptionName ;
168
169
170
+ private boolean pubSubNoLocal = false ;
171
+
169
172
private @ Nullable Boolean replyPubSubDomain ;
170
173
171
174
private @ Nullable QosSettings replyQosSettings ;
172
175
173
- private boolean pubSubNoLocal = false ;
174
-
175
176
private @ Nullable MessageConverter messageConverter ;
176
177
177
178
private @ Nullable ExceptionListener exceptionListener ;
@@ -180,6 +181,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
180
181
181
182
private @ Nullable ObservationRegistry observationRegistry ;
182
183
184
+ private boolean acknowledgeAfterListener = true ;
185
+
183
186
private boolean exposeListenerSession = true ;
184
187
185
188
private boolean acceptMessagesWhileStopping = false ;
@@ -484,12 +487,7 @@ public void setReplyPubSubDomain(boolean replyPubSubDomain) {
484
487
*/
485
488
@ Override
486
489
public boolean isReplyPubSubDomain () {
487
- if (this .replyPubSubDomain != null ) {
488
- return this .replyPubSubDomain ;
489
- }
490
- else {
491
- return isPubSubDomain ();
492
- }
490
+ return (this .replyPubSubDomain != null ? this .replyPubSubDomain : isPubSubDomain ());
493
491
}
494
492
495
493
/**
@@ -575,6 +573,37 @@ public void setObservationRegistry(@Nullable ObservationRegistry observationRegi
575
573
return this .observationRegistry ;
576
574
}
577
575
576
+ /**
577
+ * Specify whether the listener container should automatically acknowledge
578
+ * each JMS Message after the message listener returned. This applies in
579
+ * case of client acknowledge modes, including vendor-specific modes but
580
+ * not in case of auto-acknowledge or a transacted JMS Session.
581
+ * <p>As of 6.2, the default is {@code true}: The listener container will
582
+ * acknowledge each JMS Message even in case of a vendor-specific mode,
583
+ * assuming client-acknowledge style processing for custom vendor modes.
584
+ * <p>If the provided listener prefers to manually acknowledge each message in
585
+ * the listener itself, in combination with an "individual acknowledge" mode,
586
+ * switch this flag to {code false} along with the vendor-specific mode.
587
+ * @since 6.2.6
588
+ * @see #setSessionAcknowledgeMode
589
+ * @see #setMessageListener
590
+ * @see Message#acknowledge()
591
+ */
592
+ public void setAcknowledgeAfterListener (boolean acknowledgeAfterListener ) {
593
+ this .acknowledgeAfterListener = acknowledgeAfterListener ;
594
+ }
595
+
596
+ /**
597
+ * Determine whether the listener container should automatically acknowledge
598
+ * each JMS Message after the message listener returned.
599
+ * @since 6.2.6
600
+ * @see #setAcknowledgeAfterListener
601
+ * @see #isClientAcknowledge(Session)
602
+ */
603
+ public boolean isAcknowledgeAfterListener () {
604
+ return this .acknowledgeAfterListener ;
605
+ }
606
+
578
607
/**
579
608
* Set whether to expose the listener JMS Session to a registered
580
609
* {@link SessionAwareMessageListener} as well as to
@@ -812,7 +841,7 @@ protected void commitIfNecessary(Session session, @Nullable Message message) thr
812
841
JmsUtils .commitIfNecessary (session );
813
842
}
814
843
}
815
- else if (message != null && isClientAcknowledge (session )) {
844
+ else if (message != null && isAcknowledgeAfterListener () && isClientAcknowledge (session )) {
816
845
message .acknowledge ();
817
846
}
818
847
}
0 commit comments