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



我刚开始使用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)。

作为参考,自2.8以来,RecoveringBatchErrorHandlerRetryingBatchErrorHandler已被弃用,而支持DefaultErrorHandler

最新更新