spring cloud gateway集成hystrix全局断路器
生活随笔
收集整理的這篇文章主要介紹了
spring cloud gateway集成hystrix全局断路器
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
pom.xml添加依賴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
在配置文件中,增加spring.cloud.gateway.default-filters:
default-filters: - name: Hystrixargs:name: fallbackcmdfallbackUri: forward:/fallbackcontroller一定要注意是spring.cloud.gateway.default-filters這個配置節(jié)。
?
如上的配置,將會使用HystrixCommand打包剩余的過濾器,并命名為fallbackcmd,我們還配置了可選的參數(shù)fallbackUri,降級邏輯被調(diào)用,請求將會被轉(zhuǎn)發(fā)到URI為/fallbackcontroller的控制器處理。定義降級處理如下:
@RequestMapping(value = "/fallbackcontroller") public Map<String, String> fallBackController() {Map<String, String> res = new HashMap();res.put("code", "-100");res.put("data", "service not available");return res; }?
此時可以設(shè)置hystrix超時時間(毫秒) ,默認只有2秒
hystrix:command:default:execution:isolation:thread:timeoutInMilliseconds: 30000示例代碼:
https://github.com/wanghongqi/springcloudconsul_test/tree/master/springtest_gateway
?
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的spring cloud gateway集成hystrix全局断路器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【286页干货】一天搞懂深度学习(台湾资
- 下一篇: angular接口传参