Search code examples
spring-kafka

spring kafka batch error handler implementation- need to know some examples


Just would like to know on how to work with the batch error handler. Would like to see some examples.

My requirement is when batch consumer consumes the list or records if any poison pill (invalid record- different format) encounter, we need to just skip the record.

Thanks


Solution

  • In the latest version (2.8), use the DefaultErrorHandler https://docs.spring.io/spring-kafka/docs/current/reference/html/#default-eh

    In previous versions, use the RecoveringBatchErrorHandler https://docs.spring.io/spring-kafka/docs/2.7.9/reference/html/#recovering-batch-eh

    In either case, you throw a BatchListenerFailedException with information about which record in the batch failed; the error handler will commit the offsets for the records before that one and retry (or skip) the failed record.

    You can configure the error handler to indicate which exceptions are retryable, and which are not.