Search code examples
apache-kafkakafka-consumer-apispring-kafka

Kafka Consumes unprocessable messages - How to reprocess broken messages later?


We are implementing a Kafka Consumer using Spring Kafka. As I understand correctly if processing of a single message fails, there is the option to

  • Don't care and just ACK
  • Do some retry handling using a RetryTemplate
  • If even this doesn't work do some custom failure handling using a RecoveryCallback

I am wondering what your best practices are for that. I think of simple application exceptions, such as DeserializationException (for JSON formatted messages) or longer local storage downtime, etc. Meaning there is needed some extra work, like a hotfix deployment, to fix the broken application to be able to re-process the faulty messages.

Since losing messages (i. e. not processing them) is not an option for us, the only option left is IMO to store the faulty messages in some persistence store, e. g. another "faulty messages" Kafka topic for example, so that those events can be processed again at a later time and there is no need to stop event processing totally.

How do you handle these scenarios?


Solution

  • One example is Spring Cloud Stream, which can be configured to publish failed messages to another topic errors.foo; users can then copy them back to the original topic to try again later.

    This logic is done in the recovery callback.