Hystrix:不能跳闸断路器

时间:2018-04-25 00:19:07

标签: hystrix

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

CircuitBreakerRequestVolumeThreshold=20    
CircuitBreakerErrorThresholdPercentage=50    
MetricsRollingStatisticalWindowInMilliseconds=10000ms 

我认为这意味着在10秒钟的窗口内,如果在20个连续请求中有10个处理异常,电路将会中断。
我有一个名为MyCommand的类,它扩展了HystrixCommand。我创建它的20个对象并按顺序调用execute。但是我似乎没有把电路绊倒,因为它永远不会进入我的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;    
    }

1 个答案:

答案 0 :(得分:1)

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