【问题标题】:Can spring cloud stream kafka binder allow/deny retry for specific exceptions?spring cloud stream kafka binder 可以允许/拒绝特定异常的重试吗?
【发布时间】:2020-02-12 13:53:33
【问题描述】:

是否可以在 application.yml 中添加一个属性,以包括/排除某些例外情况,使其在下面定义的策略中被重试?我发誓我在某处读到过,这有一个属性,但现在我再也找不到它了。任何帮助将不胜感激。

spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: localhost:9092
      bindings:
        topic-in:
          destination: topic
          contentType: application/json
          group: topic-group
          consumer:
            max-attempts: 3 
            backOffInitialInterval: 1000
            backOffMaxInterval: 1000
            backOffMultiplier: 3

【问题讨论】:

    标签: spring-boot spring-kafka spring-cloud-stream spring-retry


    【解决方案1】:

    请参阅文档Retry Template

    RetryTemplate 是 Spring Retry 库的一部分。虽然涵盖 RetryTemplate 的所有功能超出了本文档的范围,但我们将提及以下与 RetryTemplate 专门相关的消费者属性:

    ...

    defaultRetryable

    监听器抛出的未在retryableExceptions 中列出的异常是否可重试。

    默认值:真。

    可重试异常

    键中的 Throwable 类名称和值中的布尔值的映射。指定将重试或不会重试的那些异常(和子类)。另见defaultRetriable。示例:spring.cloud.stream.bindings.input.consumer.retryable-exceptions.java.lang.IllegalStateException=false

    默认值:空。

    ...

    虽然上述设置足以满足大多数自定义要求,但它们可能无法满足某些复杂的要求,此时您可能需要提供自己的 RetryTemplate 实例。这样做...

    【讨论】:

    • 这非常适合我的需求!非常感谢你,加里!非常快速的反应。 :)
    • 很高兴知道 - 请参阅stackoverflow.com/help/someone-answers - 它会帮助其他人。
    • 知道了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2018-12-16
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多