[英]spring-kafka: DeadLetterPublishingRecoverer vs RetryTopicConfiguration
How are DefaultErrorHandler
and RetryTopicConfiguration/Builder
related? DefaultErrorHandler
和RetryTopicConfiguration/Builder
有什么关系? Can they work together or does one take precedence over the other?他们可以一起工作还是一个优先于另一个?
I am trying to setup my consumption such that我正在尝试设置我的消费量
FixedBackOff(attempts = 3, interval = 5s)
)重试一定次数( FixedBackOff(attempts = 3, interval = 5s)
)RetryTopicConfiguration.useSingleTopicForFixedDelays
works)使用单个主题进行重试( RetryTopicConfiguration.useSingleTopicForFixedDelays
有效)main-topic-name.retry
).自定义重试主题的名称(比如main-topic-name.retry
)。 Have not found any class/method that lets me do that.还没有找到任何让我这样做的类/方法。main-topic-name.deadLetter
).如果重试次数用尽,则使用自定义名称 ( main-topic-name.deadLetter
) 发送到死信。 DeadLetterPublishingRecoverer
second parameter BiFunction
should work but looks like the DL topic has to created beforehand. DeadLetterPublishingRecoverer
第二个参数BiFunction
应该可以工作,但看起来 DL 主题必须事先创建。 Not entirely sure.不完全确定。Observations观察
DeadLetterPublishingRecoverer
without retry related property configuration, I am able to retry with the hard-coded FixedBackOff
( return new DefaultErrorHandler(recoverer, new FixedBackOff(5000, 3));
)如果我在没有重试相关属性配置的情况下使用DeadLetterPublishingRecoverer
,我可以使用硬编码的FixedBackOff
重试( return new DefaultErrorHandler(recoverer, new FixedBackOff(5000, 3));
)DeadLetterPublishingRecoverer
with retry related property configuration, the above hard-coded backoff is overridden.如果我将DeadLetterPublishingRecoverer
与重试相关的属性配置一起使用,则会覆盖上述硬编码的退避。 I am puzzled how the override happens even though I am supplying a configured error handler instance.即使我提供了一个配置的错误处理程序实例,我也很困惑覆盖是如何发生的。DeadLetterPublishingRecoverer
only, I don't get a separate retry topic.通过仅使用DeadLetterPublishingRecoverer
,我没有获得单独的重试主题。RetryTopicConfiguration
(with or without recoverer), I get a retry topic, not with the name I want but default one.通过使用RetryTopicConfiguration
(带或不带恢复器),我得到一个重试主题,不是我想要的名称,而是默认名称。 However, the dead letter topic used is not mine, the one supplied in DeadLetterPublishingRecoverer
but the default one ( ....-dlt
)但是,使用的死信主题不是我的,是在DeadLetterPublishingRecoverer
中提供的,而是默认的( ....-dlt
)I am hoping people would have come across this and have a found a solution to the way I intend to setup my consumption (numbered list above).我希望人们会遇到这个问题并找到我打算设置消费方式的解决方案(上面的编号列表)。
Help appreciated帮助表示赞赏
Your question seems to be more about topic naming than about DeadLetterPubishingRecoverer
.您的问题似乎更多是关于主题命名而不是关于DeadLetterPubishingRecoverer
。
If you just need to change the topics' suffix, such as main-topic-name.retry
and main-topic-name.deadLetter
, you can use methods in the RetryTopicConfigurationBuilder
, such as:如果只需要更改主题的后缀,例如main-topic-name.retry
和main-topic-name.deadLetter
,可以使用RetryTopicConfigurationBuilder
中的方法,例如:
@Bean
public RetryTopicConfiguration myRetryTopic(KafkaTemplate<String, MyOtherPojo> template) {
return RetryTopicConfigurationBuilder
.newInstance()
.useSingleTopicForFixedDelays()
.retryTopicSuffix(".retry")
.dltTopicSuffix(".deadletter")
.create(template);
}
If you need more customization than that, you can also provide a RetryTopicNamesProviderFactory
.如果您需要更多自定义,您还可以提供RetryTopicNamesProviderFactory
。
Refer to the feature's topic naming documentation - versions 2.8.x and 2.9.x for more details.有关更多详细信息,请参阅功能的主题命名文档 - 版本2.8.x和2.9.x。
About the interaction with DefaultErrorHandler
and DeadLetterPubishingRecoverer
, the way the feature works is the framework will setup its own DEH
and DLPR
to handle record forwarding to the retry topics and dlt.关于与DefaultErrorHandler
和DeadLetterPubishingRecoverer
的交互,该功能的工作方式是框架将设置自己的DEH
和DLPR
来处理记录转发到重试主题和 dlt。
You can customize these components if necessary - for 2.9.x
see this section of the documentation on how to configure it.如有必要,您可以自定义这些组件 - 对于2.9.x
,请参阅文档的此部分以了解如何配置它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.