apache-kafka - spring kafka setErrorHandler deprecated replacement (boot 2.6.4)

标签 apache-kafka spring-kafka

在 spring boot 2.6.4 上,此方法已弃用。

public ConcurrentKafkaListenerContainerFactory<Object, Object> kafkaListenerContainerFactory(
            ConcurrentKafkaListenerContainerFactoryConfigurer configurer) {
        var factory = new ConcurrentKafkaListenerContainerFactory<Object, Object>();
        configurer.configure(factory, consumerFactory());

        // deprecated
        factory.setErrorHandler(new GlobalErrorHandler());

        return factory;
    }

全局错误处理类

public class GlobalErrorHandler implements ConsumerAwareErrorHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalErrorHandler.class);

    @Override
    public void handle(Exception thrownException, ConsumerRecord<?, ?> data, Consumer<?, ?> consumer) {
        // my custom global logic (e.g. notify ops team via slack)
    }

}

这个的替换样本是什么?文档说我应该使用 setCommonErrorHandler,但是如何实现 CommonErrorHandler 接口(interface),因为那里没有方法可以被覆盖。

重点是,我必须根据特定条件(消息 tpye,在 kafka 消息头上可用)向 ops 团队发送松弛通知

这不是阻塞,只是一个烦人的已弃用消息。 谢谢

最佳答案

请参阅 Spring for Apache Kafka 文档;遗留错误处理程序被替换为 CommonErrorHandler 实现。

有什么新鲜事?

https://docs.spring.io/spring-kafka/docs/current/reference/html/#x28-eh

The legacy GenericErrorHandler and its sub-interface hierarchies for record an batch listeners have been replaced by a new single interface CommonErrorHandler with implementations corresponding to most legacy implementations of GenericErrorHandler. See Container Error Handlers for more information.

容器错误处理程序

https://docs.spring.io/spring-kafka/docs/current/reference/html/#error-handlers

Starting with version 2.8, the legacy ErrorHandler and BatchErrorHandler interfaces have been superseded by a new CommonErrorHandler. These error handlers can handle errors for both record and batch listeners, allowing a single listener container factory to create containers for both types of listener. CommonErrorHandler implementations to replace most legacy framework error handler implementations are provided and the legacy error handlers deprecated. The legacy interfaces are still supported by listener containers and listener container factories; they will be deprecated in a future release.

关于apache-kafka - spring kafka setErrorHandler deprecated replacement (boot 2.6.4),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71330929/

相关文章:

apache-kafka - 不同计算机上的 Kafka 生产者和消费者无法通信

apache-kafka - Spring Kafka 消费者无法消费记录

使用 appication.yml/properties 具有不同属性配置的 Spring Boot Kafka 多个消费者

apache-kafka - 没有输入主题的拓扑将不会创建流​​线程和全局线程

apache-kafka - 在没有 Confluent 组件的情况下从 Kafka 生成和使用 Avro 消息

apache-kafka - 如何在不手动分配分区的情况下实现 Exactly-Once Kafka Consumer

spring-boot - 将主题名称数组列表传递给@KafkaListener

java - Kafka Streams - 处理超时

java - Spring 卡夫卡|如何使 DeserializationException 可重试?

rest - Kafka 消息 VS REST 调用