【发布时间】:2021-12-02 18:51:16
【问题描述】:
我们使用的是 Spring kafka 2.7 非阻塞重试机制。我们想记录在 @KafkaListener 方法中使用数据时引发的错误。
在上面的例子中我们可以看到,有一个 RuntimeException 被抛出。但是该异常不会被记录,而是我们会得到Seek to current after exception ....。
// our configuration
@Bean
public ConcurrentKafkaListenerContainerFactory<String, Object> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, Object> factory
= new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
return factory;
}
@Bean
public RetryTopicConfiguration retryTopicConfiguration(KafkaTemplate<String, Object> template) {
List<Class<? extends Throwable>> throwableList = Arrays.asList(IllegalArgumentException.class,
IllegalAccessException.class);
return RetryTopicConfigurationBuilder
.newInstance()
.dltHandlerMethod(XYZ.class, "xyz")
.exponentialBackoff(delayMs, backoffMultiplier, maxIntervalInMs)
.maxAttempts(retryAttempt)
.notRetryOn(throwableList)
.doNotAutoCreateRetryTopics()
.listenerFactory(kafkaListenerContainerFactory())
.setTopicSuffixingStrategy(TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
.create(template);
}
【问题讨论】:
-
@GaryRussell:请帮忙。
标签: java spring-boot apache-kafka spring-kafka spring-retry