SetErrorHandler in not supproted in Kafka 3.1.1 version and deprecated in 3.0.14 what is the replacement

35 Views Asked by At

In Spring boot 3.1.2, this method is deprecated. This is the KafkaConfig class:

public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory() {
    ConcurrentKafkaListenerContainerFactory<String, String> factory = new 
        ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    //        deprecated
    factory.setErrorHandler((exception, data) -> {
        log.error("exception occurred while processing data {} and the data is {}",
            exception, data);
    });
    return factory;
}

What is the replacement sample for this? The doc says, I should use setCommonErrorHandler, but how to implement the CommonErrorHandler interface, as no method to be overriden is there?

This is not blocking, just an annoying deprecated message though. Thanks

1

There are 1 best solutions below

0
Artem Bilan On

It is mentioned in the Javadocs of that deprecated method:

/**
 * Set the error handler to call when the listener throws an exception.
 * @param errorHandler the error handler.
 * @since 2.2
 * @deprecated in favor of {@link #setCommonErrorHandler(CommonErrorHandler)}
 * @see #setCommonErrorHandler(CommonErrorHandler)
 */
@Deprecated(since = "2.8", forRemoval = true) // in 3.1
public void setErrorHandler(org.springframework.kafka.listener.ErrorHandler errorHandler) {

Also see docs for more info: https://docs.spring.io/spring-kafka/reference/kafka/annotation-error-handling.html