Search code examples
spring-kafka

DefaultErrorHandler doesn't log not retryable exceptions


Not retryable exceptions are not logged in DefaultErrorHandler when used with DeadLetterPublishingRecoverer.

@Bean
public CommonErrorHandler consumerErrorHandler(KafkaTemplate<String, KafkaMessage> kafkaTemplate) {
    var errorHandler = new DefaultErrorHandler(new DeadLetterPublishingRecoverer(kafkaTemplate), kafkaConsumerRetryProperties.getBackoffPolicy());
    errorHandler.addNotRetryableExceptions(NullPointerException.class);
    return errorHandler;
}

In this case NullPointerException is not logged whatsoever when thrown in method annotated with @KafkaListener


Solution

  • Feel free to open an issue on GitHub. In the meantime, you could subclass the DLPR and log the exception in accept() before calling super.accept().