简体   繁体   English

spring-kafka:DeadLetterPublishingRecoverer vs RetryTopicConfiguration

[英]spring-kafka: DeadLetterPublishingRecoverer vs RetryTopicConfiguration

How are DefaultErrorHandler and RetryTopicConfiguration/Builder related? DefaultErrorHandlerRetryTopicConfiguration/Builder有什么关系? Can they work together or does one take precedence over the other?他们可以一起工作还是一个优先于另一个?

I am trying to setup my consumption such that我正在尝试设置我的消费量

  1. Retry a certain number of times ( FixedBackOff(attempts = 3, interval = 5s) )重试一定次数( FixedBackOff(attempts = 3, interval = 5s)
  2. Use a single topic for retry ( RetryTopicConfiguration.useSingleTopicForFixedDelays works)使用单个主题进行重试( RetryTopicConfiguration.useSingleTopicForFixedDelays有效)
  3. Customize the name of the retry topic (say main-topic-name.retry ).自定义重试主题的名称(比如main-topic-name.retry )。 Have not found any class/method that lets me do that.还没有找到任何让我这样做的类/方法。
  4. If the retries are exhausted, then post to a dead letter with a customized name ( 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观察

  • If I use 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));
  • If I use 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.即使我提供了一个配置的错误处理程序实例,我也很困惑覆盖是如何发生的。
  • By using DeadLetterPublishingRecoverer only, I don't get a separate retry topic.通过仅使用DeadLetterPublishingRecoverer ,我没有获得单独的重试主题。
  • By using 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.retrymain-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.x2.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.关于与DefaultErrorHandlerDeadLetterPubishingRecoverer的交互,该功能的工作方式是框架将设置自己的DEHDLPR来处理记录转发到重试主题和 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.

相关问题 spring-kafka:如何为 ConcurrentMessageListenerContainer 提供 RetryTopicConfiguration? - spring-kafka: How to provide RetryTopicConfiguration to ConcurrentMessageListenerContainer? 使用 DeadLetterPublishingRecoverer 处理 Spring-kafka 错误 - Spring-kafka error handling with DeadLetterPublishingRecoverer spring-kafka: RetryTopicConfiguration 自定义名称用于重试和死信主题 - spring-kafka: RetryTopicConfiguration with custom names for retry and dead letter topics DeadLetterPublishingRecoverer 中的 Kafka 序列化程序与 Spring 消息转换器 - Kafka Serializers vs Spring Message Converters in DeadLetterPublishingRecoverer Spring-Kafka 使用 DeadLetterPublishingRecoverer 将自定义记录而不是失败记录发送到 DLT - Spring-Kafka Sending custom record instead of failed record using DeadLetterPublishingRecoverer to a DLT spring-kafka:不考虑带有 DeadLetterPublishingRecoverer(BiFunction) 的 DefaultErrorHandler。 未创建深度学习主题 - spring-kafka: DefaultErrorHandler with DeadLetterPublishingRecoverer(BiFunction) not considered. No DL topic created Spring-Kafka 与 kafka-clients 直接对比 - Spring-Kafka vs. kafka-clients directly spring-kafka 指标不可用 - spring-kafka metrics not available Spring-Kafka 中的 poll() 和 commitAsync() - poll() and commitAsync() in Spring-Kafka spring-kafka 监听器签名 - spring-kafka listener signature
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM