Spring Kafka批处理选项:使用SeekToCurrentBatchErrorHandler的ClassCastException

时间:2018-10-26 11:32:37

标签: spring apache-kafka spring-kafka

Trying to configure the Factory as below:
private ConcurrentKafkaListenerContainerFactory<Integer, String> getKafkaContainerFactory()
        throws IOException {
    ConcurrentKafkaListenerContainerFactory<Integer, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(this.getConsumerFactory());//DefaultKafkaConsumerFactory
    factory.setAutoStartup(true);
    ContainerProperties props = factory.getContainerProperties();
    props.setAckMode(AbstractMessageListenerContainer.AckMode.BATCH);
    props.setAckOnError(false);
    props.setBatchErrorHandler(new SeekToCurrentBatchErrorHandler());
    return factory;
}

具有:

Kafka version : 1.0.2, spring-kafka:2.1.10.RELEASE & springBootVersion = '2.0.5.RELEASE'

得到以下异常:

  

上下文初始化期间遇到的异常-取消刷新尝试:org.springframework.context.ApplicationContextException:无法启动bean'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry';嵌套异常是java.lang.ClassCastException:org.springframework.kafka.listener.SeekToCurrentBatchErrorHandler无法转换为org.springframework.kafka.listener.ErrorHandler

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

要创建批处理侦听器容器,请添加factory.setBatchListener(true);