Kafka Exception Handling (Retry)
By default, any exceptions that were throw in @KafkaListener
will be retried.
The default setitng is DefaultErrorHandler
2023-11-28T10:46:47.161+11:00 ERROR 21985 --- [listener1-0-C-1] o.s.kafka.listener.DefaultErrorHandler : Backoff FixedBackOff{interval=0, currentAttempts=10, maxAttempts=9} exhausted for mytopic-0@7
With 10
attempts to retry.
Retry happens when there is an exception throws in @KafkaListener
For example the following code will trigger retry:
@Service
public class DefaultEventListener {
@KafkaListener(id = "listener1", topics = TOPIC_NAME, containerFactory = "defaultMessageListenerFactory")
public void listen(String event) {
System.out.println("Listened events: " + event);
throw new RuntimeException("Some exception");
}
}