springcloud?feign集成hystrix方式
本章介紹feign集成hystrix
1、增加pom依賴`
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency>
2、啟動(dòng)類中增加注解
@EnableHystrix
3、增加feign接口fallback以及相關(guān)配置
DemoService
@ConditionalOnProperty(name = "app.host.abcurl")
@FeignClient(value = "demo-service", url = "${app.host.abcurl}" ,fallback = DemoServiceFallbackImpl .class)
public interface DemoService {
@GetMapping("/v1/api/getCateData")
ApiResponse<Page<Object>> getCateData(@RequestParam Map<String,String> params);
@GetMapping("/v1/api/getProductData")
ApiResponse<Page<Detail>> getProductData(@RequestParam Map<String,String> params);
}DemoServiceFallbackImpl
@Slf4j
@Component
public class DemoServiceFallbackImpl implements DemoService {
@Override
public ApiResponse<Page<Object>> getCateData (Map<String, String> params) {
log.warn("DemoServiceFallbackImpl getCateData fail");
return null;
}
@Override
public ApiResponse<Page<Detail>> getProductData(Map<String, String> params) {
log.warn("DemoServiceFallbackImpl getProductData fail");
return null;
}
}4、增加yml相關(guān)配置
feign:
httpclient:
enabled: true
hystrix:
enabled: true
hystrix:
command:
default:
execution:
timeout:
enabled: true
isolation:
thread:
timeoutInMilliseconds: 1000 //該配置需要比ribbon超時(shí)時(shí)間長(zhǎng)
circuitBreaker:
requestVolumeThreshold: 1000
threadpool:
default:
coreSize: 60
maxQueueSize: 200
queueSizeRejectionThreshold: 200
ribbon:
ReadTimeout: 500
ConnectTimeout: 500
ExecTimeout: 500
MaxAutoRetries: 1 //最好設(shè)置超時(shí)重試這里如果需要查看hystrix監(jiān)控,可以集成Hystrix Dashboard,詳情參考
下圖是我集成grafana 、prometheus的監(jiān)控圖


總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot項(xiàng)目調(diào)優(yōu)及垃圾回收器的比較詳解
這篇文章主要介紹了SpringBoot項(xiàng)目調(diào)優(yōu)及垃圾回收器的比較詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
springboot+mybatis快速插入大量數(shù)據(jù)的具體實(shí)現(xiàn)
最近導(dǎo)入表格數(shù)據(jù)時(shí)需要同時(shí)插入修改大量數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于springboot+mybatis快速插入大量數(shù)據(jù)的具體實(shí)現(xiàn),文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
詳解Java?redis中緩存穿透?緩存擊穿?雪崩三種現(xiàn)象以及解決方法
緩存穿透是指緩存和數(shù)據(jù)庫(kù)中都沒有的數(shù)據(jù),而用戶不斷發(fā)起請(qǐng)求,如發(fā)起為id為“-1”的數(shù)據(jù)或id為特別大不存在的數(shù)據(jù)。這時(shí)的用戶很可能是攻擊者,攻擊會(huì)導(dǎo)致數(shù)據(jù)庫(kù)壓力過大2022-01-01
如何使用Java實(shí)現(xiàn)請(qǐng)求deepseek
這篇文章主要為大家詳細(xì)介紹了如何使用Java實(shí)現(xiàn)請(qǐng)求deepseek功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2025-02-02
Java數(shù)組轉(zhuǎn)換為L(zhǎng)ist的四種方式
這篇文章主要介紹了Java開發(fā)技巧數(shù)組轉(zhuǎn)List的四種方式總結(jié),每種方式結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-09-09
Java使用POI導(dǎo)出Excel(一):?jiǎn)蝧heet
這篇文章介紹了Java使用POI導(dǎo)出Excel的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-10-10

