Hystrix使用配置文件方式配置熔断器参数
2018-07-21 本文已影响24人
HmilyMing
之前的关于断路器的配置都是在代码里面配置的,如下图所示,不利于后期的维护

现在要改成用配置文件的方式进行,我们针对超时时间来做一个配置
Hystrix全局超时时间配置如下图所示,表示3秒
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 3000

在controller里面新增加一个testHystrixCommand5方法,直接加HystrixCommand注解即可

通过number=2测试接口访问成功

因为它里面调用的msg2方法里面有2秒的线程等待时间,现在配置了最长等待时间为3秒,所以这时候number=1请求msg2是可以的

现在全局的超时时间为3秒,我想针对testHystrixCommand5方法单独配1秒的超时时间,配置如下(注意了,这里具体的方法名而不是GetMapping里面的URL!!!)

针对testHystrixCommand5的单独配置生效了

代码在:https://github.com/hmilyos/springCloud-order.git hystrixProper分支
其他全局配置项就参考这种方式即可。