日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringCloud熔断器介绍

發布時間:2024/4/13 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringCloud熔断器介绍 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Hystrix概念

Hystrix?是一個供分布式系統使用,提供延遲和容錯功能,保證復雜的分布系統在面臨不可避免的失敗時,仍能有其彈性。

比如系統中有很多服務,當某些服務不穩定的時候,使用這些服務的用戶線程將會阻塞,如果沒有隔離機制,系統隨時就有可能會掛掉,從而帶來很大的風險。SpringCloud使用Hystrix組件提供斷路器、資源隔離與自我修復功能。下圖表示服務B觸發了斷路器,阻止了級聯失敗

feign結合Hystrix使用

在service的pom中添加依賴

<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-ribbon</artifactId></dependency><!--hystrix依賴,主要是用 @HystrixCommand --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><!--服務注冊--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><!--服務調用--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

在配置文件中添加hystrix配置

#開啟熔斷機制 feign.hystrix.enabled=true # 設置hystrix超時時間,默認1000ms hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000

在service-edu的client包里面創建熔斷器的實現類

@Component public class VodFileDegradeFeignClient implements VodClient {@Overridepublic R removeVideo(String videoId) {return R.error().message("time out");}@Overridepublic R removeVideoList(List videoIdList) {return R.error().message("time out");} }

修改VodClient接口的注解

@FeignClient(name = "service-vod", fallback = VodFileDegradeFeignClient.class) @Component public interface VodClient {@DeleteMapping(value = "/eduvod/vod/{videoId}")public R removeVideo(@PathVariable("videoId") String videoId);@DeleteMapping(value = "/eduvod/vod/delete-batch")public R removeVideoList(@RequestParam("videoIdList") List videoIdList); }

?

總結

以上是生活随笔為你收集整理的SpringCloud熔断器介绍的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。