Spring Kafka - 使用哪个批处理错误处理程序?

Spring Kafka - which batch error handler to use?

我刚开始使用spring-kafka 2.6.4。 我创建了批量轮询消息的消费者工厂:

@Bean
public ConcurrentKafkaListenerContainerFactory<String, String>
            kafkaListenerContainerFactory(MeterRegistry meterRegistry) {
    ConcurrentKafkaListenerContainerFactory<String, String> factory =
        new ConcurrentKafkaListenerContainerFactory<>();
    factory.setConsumerFactory(consumerFactory());
    factory.setConcurrency(kafkaProperties.getTopicConcurrency());
    factory.setBatchListener(true);
    factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.BATCH);
    return factory;
}

现在我想定义正确的错误处理程序,使消费者停留在失败的记录上,而不是轮询下一批。

我应该使用哪个错误处理程序?

谢谢。

RecoveringBatchErrorHandler (https://docs.spring.io/spring-kafka/docs/current/reference/html/#recovering-batch-eh) 现在是首选(自 2.5 起默认)批处理错误处理程序。您的侦听器可以抛出特定异常以指示批处理中的哪条记录失败。

还有一个RetryingBatchErrorHandler(https://docs.spring.io/spring-kafka/docs/current/reference/html/#retrying-batch-eh).