【问题标题】:can I use hystrix to call up a failed request again?我可以使用 hystrix 再次调用失败的请求吗?
【发布时间】:2020-09-13 17:47:09
【问题描述】:

我有一个 feign 客户端,它每 60 秒向另一个微服务发送一个请求。在这个控制器上,我使用带有用户配置的 HystrixCommand 注释(只是试验)。我还有一个后备方法,当请求失败时我会使用该方法。 但是,预期的数据对我来说非常敏感,因此从 fallback 方法发送空数据是没有意义的。

问题:如何以任意间隔再执行 2-3 次失败的请求? Hystrix 有这个功能吗?

我有想法在回退方法中再次调用请求并将执行的请求数保存在某处,每次将它们与限制变量进行比较,但我不喜欢它。

 @HystrixCommand(
            threadPoolKey = "currencyThreadPool",
            threadPoolProperties = {
                    @HystrixProperty(name = "coreSize", value = "30"),
                    @HystrixProperty(name = "maxQueueSize", value = "10")},
            commandProperties = {
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
                    @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "90"),
                    @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),
                    @HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "15000"),
                    @HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "5")}
    )

【问题讨论】:

    标签: spring-boot hystrix feign


    【解决方案1】:

    最后,我使用了 Spring Retry 库,完全满足了我的要求。

    @Retryable(value = {ConnectException.class, FeignException.class}, maxAttempts = 4,
            backoff = @Backoff(delay = 5000, maxDelay = 80000, multiplier = 4))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2019-09-13
      • 2011-09-12
      • 2019-12-31
      • 1970-01-01
      • 2016-07-04
      • 1970-01-01
      相关资源
      最近更新 更多