apache-kafkamicronaut-kafka

Retrying a failed kafka message using Micronaut listener


I have used kafka integrations with spring applications in the past and there is a retry mechanism already implemented. But our team decided to spin up a micronaut service since we found some nice benefits.

I added the micronaut-kafka dependency and set up a listener. The problem is, if a message causes my listener to throw, the exception is logged but the offset is committed.

Is there a way to configure like a number of retries for each message?


Solution

  • As you can see in micronaut documentation:

    You can configure an errorStrategy on the @KafkaListener annotation

    @KafkaListener(
       value = "myGroup", 
       errorStrategy = @ErrorStrategy(value = RETRY_ON_ERROR, retryDelay = "50ms", retryCount=3)
    )