From c5904b1e5d24122a0115bfbc640337deac6b8e78 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Thu, 1 Aug 2024 14:15:52 -0400 Subject: [PATCH] GH-3400: Clarify manual ack semantics Fixes #3400 --- .../pages/kafka/receiving-messages/listener-annotation.adoc | 4 ++++ .../listener/adapter/MessagingMessageListenerAdapter.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc index f719d178b9..587b270a63 100644 --- a/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc +++ b/spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/receiving-messages/listener-annotation.adoc @@ -173,7 +173,11 @@ If seekPosition set `TIMESTAMP`, `initialOffset` means timestamp. == Manual Acknowledgment When using manual `AckMode`, you can also provide the listener with the `Acknowledgment`. +To activate the manual `AckMode`, you need to set the ack-mode in `ContainerProperties` to the appropriate manual mode. The following example also shows how to use a different container factory. +This custom container factory must set the `AckMode` to a manual type by calling the `getContainerProperties()` and then calling `setAckMode` on it. +Otherwise, the `Acknowledgment` object will be null. + [source, java] ---- diff --git a/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java b/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java index dcf17e0d0f..483c389472 100644 --- a/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java +++ b/spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/MessagingMessageListenerAdapter.java @@ -90,6 +90,7 @@ * @author Nathan Xu * @author Wang ZhiYang * @author Huijin Hong + * @author Soby Chacko */ public abstract class MessagingMessageListenerAdapter implements ConsumerSeekAware, AsyncRepliesAware { @@ -440,8 +441,7 @@ private RuntimeException checkAckArg(@Nullable Acknowledgment acknowledgment, Me if (this.hasAckParameter && acknowledgment == null) { return new ListenerExecutionFailedException("invokeHandler Failed", new IllegalStateException("No Acknowledgment available as an argument, " - + "the listener container must have a MANUAL AckMode to populate the Acknowledgment.", - ex)); + + "the listener container must have a MANUAL AckMode to populate the Acknowledgment.")); } return new ListenerExecutionFailedException(createMessagingErrorMessage("Listener method could not " + "be invoked with the incoming message", message.getPayload()), ex);