Retrying a failed kafka message using Micronaut listener

788 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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)
)