当前位置:
凯发ag旗舰厅登录网址下载 >
前端技术
> javascript
>内容正文
javascript
服务降级和服务熔断的区别-凯发ag旗舰厅登录网址下载
凯发ag旗舰厅登录网址下载
收集整理的这篇文章主要介绍了
服务降级和服务熔断的区别_spring cloud 熔断 隔离 服务降级
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
一、hystrix
hystrix主要实现熔断和隔离,限流的功能基本没有,通过fallback实现服务降级和快速失败。核心是hystrixcommand。配置主要包含exection、fallback、circuitbreaker、metric、threadpool等。
二、加入依赖包
三、在application.yml中加入配置
feign: hystrix: enabled: truehystrix:command:default:execution:timeout:enabled: trueisolation:strategy: threadthread:timeoutinmilliseconds: 8000interruptontimeout: trueinterruptoncancel: truefallback:enabled: trueisolation:semaphore:maxconcurrentrequests: 2四、在访问接口上实现熔断、隔离和服务降级
@hystrixcommand(commandkey = "circuitbreakercommand",threadpoolkey = "circuitbreakerpool",fallbackmethod = "circuitbreakerfallbackmethod",commandproperties = {@hystrixproperty(name = "circuitbreaker.enabled", value = "true"),@hystrixproperty(name = "circuitbreaker.requestvolumethreshold", value = "2"),@hystrixproperty(name = "circuitbreaker.errorthresholdpercentage", value = "10"),@hystrixproperty(name = "circuitbreaker.sleepwindowinmilliseconds", value = "5000")}, threadpoolproperties = {@hystrixproperty(name = "coresize", value = "5") })@getmapping("/circuitbreakerhello/{id}")public string circuitbreakerhello(@pathvariable("id") int id) {if(id==2){throw new runtimeexception("exception");}return "sucessful execution" ;}public string circuitbreakerfallbackmethod(int id) {return "param " id " is wrong. circuitbreaker has been valid"; }五、启动类上添加@enablehystrix
@springbootapplication(exclude={datasourceautoconfiguration.class}) @enablediscoveryclient @enablefeignclients @enablehystrix @mapperscan("com.sboot.dao") public class consulconsumerapplication {public static void main(string[] args) {springapplication.run(consulconsumerapplication.class, args);} }六、测试
1、在浏览器中多次刷新如下地址,导致熔断打开
2、当访问正常得路径http://localhost:8082/circuitbreakerhello/1,也走服务降级:
3、过一会,过了休眠期,再访问正常路径,可以正常访问
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的服务降级和服务熔断的区别_spring cloud 熔断 隔离 服务降级的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇:
- 下一篇: