【发布时间】:2021-09-17 00:33:06
【问题描述】:
我一直在尝试为 Spring cloud stream kafka 实现重试逻辑,这样如果在生成主题 sample-topic 的事件时抛出异常,它会再重试两次。
我在 application.properties 文件中添加了以下配置
spring.cloud.stream.bindings.processSampleEvent.destination=sample-topic
spring.cloud.stream.bindings.processSampleEvent.content-type=application/json
spring.cloud.stream.bindings.processSampleEvent.consumer.maxAttempts=2
我已经编写了列表器代码,它只记录接收到的消息并抛出 NullPointerException,以便我可以测试重试。
@StreamListener(ListenerBind.SAMPLE_CHANNEL)
public void processSampleEvent(String productEventDto) {
System.out.println("Entering listener: " + productEventDto);
throw new NullPointerException();
}
但是当通过向sample-topic 生成事件进行测试时,我看到在日志中该事件已经重试了 20 次,但我在属性中指定只尝试两次,而且当我换了 3 次,它重试了 30 次。
我对 Spring 云流很陌生,对此的任何帮助都会非常有帮助。
提前谢谢???
【问题讨论】:
标签: spring-boot spring-kafka spring-cloud-stream spring-cloud-stream-binder-kafka