3

I could not find any documentation related to this issue, hence the question.

What happens if @KafkaListener method does not call acknowledgement.acknowledge() at all when the ackModeis set to MANUAL_IMMEDIATE but exits out of the method successfully without any exceptions.

We encountered this issue in one of our consumers and lost the message (precisely the offset moved, we had expected the offset to not move since we never called acknowledgement.acknowledge()), is this expected behaviour?

The question here seems to address the same issue but never received an answer as to what would happen when there are no exceptions, as I believe the error handler & recoverer come into play only when exceptions are thrown and not during message un-acknowledged situations.

Mukund Jalan
  • 1,145
  • 20
  • 39

1 Answers1

2

There are two pointers maintained by Kafka; the committed offset and the current position.

If you don't call acknowledge(), and exit normally, the committed offset won't be moved, but the position will; you will get the next records on the next poll().

If you restart the application, you will get the same record(s) redelivered.

You must also set the Kafka consumer property enable.auto.commmit to false - spring-kafka (since 2.3) does this automatically, unless you have explicitly set it.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • We did have the `enable.auto.commmit` set to `false` but the message was not read after the service was restarted – Mukund Jalan Nov 04 '20 at 15:08
  • The framework will never commit any offsets with that setting. You can monitor commits by setting the `commitLogLevel` container property to INFO. Of course, if the next record is processed successfully, you will not get the "skipped" record again because committing the next offset will move the offset by 2. – Gary Russell Nov 04 '20 at 15:34