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
@ Nullable
158
159
private volatile Object destination ;
@@ -170,14 +171,14 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
170
171
@ Nullable
171
172
private String subscriptionName ;
172
173
174
+ private boolean pubSubNoLocal = false ;
175
+
173
176
@ Nullable
174
177
private Boolean replyPubSubDomain ;
175
178
176
179
@ Nullable
177
180
private QosSettings replyQosSettings ;
178
181
179
- private boolean pubSubNoLocal = false ;
180
-
181
182
@ Nullable
182
183
private MessageConverter messageConverter ;
183
184
@@ -190,6 +191,8 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen
190
191
@ Nullable
191
192
private ObservationRegistry observationRegistry ;
192
193
194
+ private boolean acknowledgeAfterListener = true ;
195
+
193
196
private boolean exposeListenerSession = true ;
194
197
195
198
private boolean acceptMessagesWhileStopping = false ;
@@ -500,12 +503,7 @@ public void setReplyPubSubDomain(boolean replyPubSubDomain) {
500
503
*/
501
504
@ Override
502
505
public boolean isReplyPubSubDomain () {
503
- if (this .replyPubSubDomain != null ) {
504
- return this .replyPubSubDomain ;
505
- }
506
- else {
507
- return isPubSubDomain ();
508
- }
506
+ return (this .replyPubSubDomain != null ? this .replyPubSubDomain : isPubSubDomain ());
509
507
}
510
508
511
509
/**
@@ -596,6 +594,37 @@ public ObservationRegistry getObservationRegistry() {
596
594
return this .observationRegistry ;
597
595
}
598
596
597
+ /**
598
+ * Specify whether the listener container should automatically acknowledge
599
+ * each JMS Message after the message listener returned. This applies in
600
+ * case of client acknowledge modes, including vendor-specific modes but
601
+ * not in case of auto-acknowledge or a transacted JMS Session.
602
+ * <p>As of 6.2, the default is {@code true}: The listener container will
603
+ * acknowledge each JMS Message even in case of a vendor-specific mode,
604
+ * assuming client-acknowledge style processing for custom vendor modes.
605
+ * <p>If the provided listener prefers to manually acknowledge each message in
606
+ * the listener itself, in combination with an "individual acknowledge" mode,
607
+ * switch this flag to {code false} along with the vendor-specific mode.
608
+ * @since 6.2.6
609
+ * @see #setSessionAcknowledgeMode
610
+ * @see #setMessageListener
611
+ * @see Message#acknowledge()
612
+ */
613
+ public void setAcknowledgeAfterListener (boolean acknowledgeAfterListener ) {
614
+ this .acknowledgeAfterListener = acknowledgeAfterListener ;
615
+ }
616
+
617
+ /**
618
+ * Determine whether the listener container should automatically acknowledge
619
+ * each JMS Message after the message listener returned.
620
+ * @since 6.2.6
621
+ * @see #setAcknowledgeAfterListener
622
+ * @see #isClientAcknowledge(Session)
623
+ */
624
+ public boolean isAcknowledgeAfterListener () {
625
+ return this .acknowledgeAfterListener ;
626
+ }
627
+
599
628
/**
600
629
* Set whether to expose the listener JMS Session to a registered
601
630
* {@link SessionAwareMessageListener} as well as to
@@ -833,7 +862,7 @@ protected void commitIfNecessary(Session session, @Nullable Message message) thr
833
862
JmsUtils .commitIfNecessary (session );
834
863
}
835
864
}
836
- else if (message != null && isClientAcknowledge (session )) {
865
+ else if (message != null && isAcknowledgeAfterListener () && isClientAcknowledge (session )) {
837
866
message .acknowledge ();
838
867
}
839
868
}
0 commit comments