【发布时间】:2020-07-04 07:36:18
【问题描述】:
我们正在使用 spring-kafka-2.2.8.RELEASE。我有需要帮助的特殊情况。我有 4 个主题 topic、retryTopic、successTopic 和 errorTopic。 如果 topic 失败,应重定向到 retryTopic 3 次重试尝试的位置制成。如果这些尝试失败,则必须重定向到 errorTopic。如果 topic 和 retryTopic 都成功,应重定向到 sucessTopic。这种情况已经基于问题How to retry with spring kafka version 2..2实现了。 但是现在,我遇到了一种新情况,我需要根据业务逻辑错误从 topic 侦听器内部调用 retryTopic 侦听器,而不会引发异常(它已经调用retryTopic 抛出异常并且它必须保持这种行为)。而且我还需要知道 retryTopic 在哪个重试尝试次数上被称为以下侦听器的参数。
@KafkaListener(id = "so60172304.2", topics = "retryTopic")
public void listen2(String in) {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.execute(new RetryCallback<Void, RuntimeException>() {
@Override
public Void doWithRetry(RetryContext retryContext) throws RuntimeException {
// Can I get the retry count here? It didn't work
Integer count =RetrySynchronizationManager.getContext().getRetryCount());
return this.doWithRetry(retryContext);
}
});
}
【问题讨论】: