Search code examples
springapache-kafkaspring-kafka

Spring Kafka error handling for multiple record in the same poll


I'm playing with Spring Kafka and error handling (org.springframework.kafka.listener.ErrorHandler) but what it's not clear to me is what happens when poll returns multiple records and only one of them is causing exception. As far as I understood, the other records are skipped. How to achieve instead a punctual error handling (e.g. skipping only the affected record and continue with the others)?


Solution

  • See the SeekToCurrentErrorHandler - it performs a seek on the failed record as well as any other partitions that follow the failed one in the poll results.

    When retries are exhausted, the failed record is skipped.

    A RemainingRecordsErrorHandler (sub-interface of ErrorHandler of which STCEH is an implementation) is given the list of remaining records.

    Docs here.

    With the simple error handler, which only gets the failed record, the remaining records are passed to the listener (as long as transactions are not being used).