這篇文章給大家介紹利用Springcloud怎么熔斷hystrix服務(wù),內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
1.主啟動類加上新的注解。
@EnableCircuitBreaker
2.service寫入新的熔斷控制方法
@Service public class PaymentHystrixService { @HystrixCommand(fallbackMethod = "paymentCircuitBreaker_fallback",commandProperties = { @HystrixProperty(name = "circuitBreaker.enabled", value = "true"), //是否開啟斷路器 @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"), //請求數(shù)達到后才計算 @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"), //休眠時間窗 @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"), //錯誤率達到多少跳閘 }) public String paymentCirtuitBreaker(@PathVariable("id")Integer id){ if(id<0){ throw new RuntimeException("****id不能為負數(shù)"); } String randomNum= IdUtil.simpleUUID(); return Thread.currentThread().getName()+"\t"+"調(diào)用成功,編號"+randomNum; } public String paymentCircuitBreaker_fallback(@PathVariable("id")Integer id){ return "id不能為負數(shù),請稍后重試,o(╥﹏╥)o+"+id; }
網(wǎng)站欄目:利用Springcloud怎么熔斷hystrix服務(wù)-創(chuàng)新互聯(lián)
文章出自:http://jinyejixie.com/article8/dphgop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、搜索引擎優(yōu)化、自適應(yīng)網(wǎng)站、網(wǎng)站設(shè)計公司、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)