🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
* [ ] 线程池隔离 * [ ] Hystrix自动实现依赖隔离 熔断的配置: 在需要进行熔断配置的方法上加上Hystrix的注解 ``` @HystrixCommand(commandProperties = { @HystrixProperty(name = "circuitBreaker.enabled" , value = "true"), //设置熔断 @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold" , value = "10"), @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds" , value = "1000"), @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage" , value = "60") }) ``` * Circuit Breaker : 断路器 [断路器详解,马丁](https://martinfowler.com/bliki/CircuitBreaker.html) 断路器是将受保护的对象封装在可以监控故障的断路对象里面,当故障达到一定的值,将会引发跳闸,断路器对象返回错误 * [ ] 图解(断路器模式状态机): :-: ![](https://box.kancloud.cn/189e0a0608fecb68ab2bef9a39bdd601_469x410.png) * circuitBreaker.sleepWindowInMilliseconds:时间窗口 当断路器打开,对主逻辑进行熔断之后,Hystrix会开启一个休眠时间窗口,将降级逻辑临时提升为主逻辑,当休眠时间到期,断路器将进入半开状态,释放一次请求到原来的主逻辑上,如果此次请求正常返回,那么断路器将继续闭合,主逻辑恢复,如果此次请求依然失败,断路器进入打开状态,休眠时间窗继续计时。 * circuitBreaker.requestVolumeThreshold : 设置在滚动窗口中断路器的最小请求数 * circuitBreaker.errorThresholdPercentage : 断路器打开的错误百分比条件 在配置文件中统一配置: ``` hystrix: command: default: execution: isolation: thread: timeoutInMilliseconds: 3000 getProductInfoList: execution: isolation: thread: timeoutInMilliseconds: 800 ```