【问题标题】:Hystrix: cannot trip circuit breakerHystrix:不能跳闸断路器
【发布时间】:2018-10-05 08:18:56
【问题描述】:

假设我使用默认的 Hystrix 配置:

CircuitBreakerRequestVolumeThreshold=20    
CircuitBreakerErrorThresholdPercentage=50    
MetricsRollingStatisticalWindowInMilliseconds=10000ms 

我假设这意味着在 10 秒的窗口内,如果在 20 个连续请求中处理了 10 个异常,则电路将中断。
我有一个名为 MyCommand 的类,它扩展了 HystrixCommand。我创建了 20 个对象并依次调用每个对象的执行。但我似乎没有使电路跳闸,因为它从未进入我的 getFallback 方法。我预计第 20 次执行会使电路跳闸。我哪里错了?

int i=0;    
    public MyObject run() throws Exception {    
        i++;    
        try {    
            throw new Exception("Handled exception "+i);    
        } catch (Exception e) {    
            System.out.print("Catch "+i);    
        }    
        return null;    
    }

【问题讨论】:

  • 这里有一个相关的评论:在持续时间metrics.rollingStats.timeInMilliseconds的时间跨度内,导致处理异常的操作百分比超过errorThresholdPercentage,前提是在时间跨度内通过电路的操作数至少是 requestVolumeThreshold

标签: hystrix


【解决方案1】:

如果您在命令中处理异常,则断路器将不会打开。在你的 run 方法中不要捕获异常。

【讨论】:

  • 但是,如果您可以接受 50% 的错误但不会更多,那该怎么办。我正在尝试了解上述 3 个属性。
猜你喜欢
  • 2020-10-29
  • 2019-06-27
  • 2018-07-09
  • 2016-12-11
  • 2016-08-06
  • 2015-12-06
  • 2015-06-19
  • 2016-01-11
  • 2019-07-05
相关资源
最近更新 更多