With respect to acknowledgement modes in Kafka, following are 2 documentations I found:
- Reference1: https://docs.spring.io/spring-kafka/docs/1.0.0.M1/reference/html/_reference.html#_committing_offsets
- Reference2: https://appdoc.app/artifact/org.springframework.kafka/spring-kafka/1.0.2.RELEASE/org/springframework/kafka/listener/config/ContainerProperties.html
From Reference1, it looks like the offset is committed after the processing of the message, i.e, if the Listener on Consumer side returns smoothly and does not throw exception.
From Reference2, it looks like the offset is committed after the message has been passed to the listener, i.e, even if the Listener on Consumer side throws an exception, the offset is already committed.
After testing out locally, I felt the behavior is in align with Reference1.
- Question1 - Is my understanding from reference 1 correct?
- Question2 - Suppose my listener is not a batch listener and ackMode is BATCH. How does the ack work for the below listener. Is it like spring when polls, say got 10msgs, and the passes on each message to a listener and then they are executed. At the end, if all of them execute without any error, spring offsets the commit, else it does not? Is it how BATCH works in the above scenario?
@KafkaListener(topics = "topicA", groupId = "gid")
@SendTo
public Message<Foo> listen(Bar msg)
{
//some work
}