The precise way that the circuit opening and closing occurs is as follows:
Assuming the volume across a circuit meets a certain threshold : HystrixCommandProperties.circuitBreakerRequestVolumeThreshold()
And assuming that the error percentage, as defined above exceeds the error percentage defined in : HystrixCommandProperties.circuitBreakerErrorThresholdPercentage()
Then the circuit-breaker transitions from CLOSED to OPEN.
While it is open, it short-circuits all requests made against that circuit-breaker.
After some amount of time (HystrixCommandProperties.circuitBreakerSleepWindowInMilliseconds()), the next request is let through. If it fails, the command stays OPEN for the sleep window. If it succeeds, it transitions to CLOSED and the logic in 1) takes over again.
link
HystrixCommandProperties.circuitBreakerRequestVolumeThreshold()
断路器请求次数阈
HystrixCommandProperties.circuitBreakerErrorThresholdPercentage()
断路器错误百分比阈值
HystrixCommandProperties.circuitBreakerSleepWindowInMilliseconds()
断路器休眠时间窗口
举例:
请求阈值为10;错误百分比为60;休眠时间窗口为5000毫秒;
在窗口时间内,请求次数超过10,且请求的错误次数百分比大于60%,则开启断路器熔断;持续5秒后,Hystrix向目标服务器发送询问请求,若成功则恢复,若失败则继续休眠5秒,重复上述操作;