本章介绍feign集成hystrix 1、增加pom依赖`
1 <dependency> 2 <groupid>org.springframework.cloud</groupid> 3 <artifactid>spring-cloud-starter-netflix-hystrix</artifactid> 4 </dependency>
2、启动类中增加注解@EnableHystrix
3、增加feign接口fallback以及相关配置
DemoService
1@ConditionalOnProperty(name = "app.host.abcurl") 2@FeignClient(value = "demo-service", url = "${app.host.abcurl}" ,fallback = DemoServiceFallbackImpl .class) 3public interface DemoService { 4 5 @GetMapping("/v1/api/getCateData") 6 ApiResponse<page<object>> getCateData(@RequestParam Map<string,string> params); 7 8 @GetMapping("/v1/api/getProductData") 9 ApiResponse<page<detail>> getProductData(@RequestParam Map<string,string> params); 10}
DemoServiceFallbackImpl
1@Slf4j 2@Component 3public class DemoServiceFallbackImpl implements DemoService { 4 5 @Override 6 public ApiResponse<page<object>> getCateData (Map<string, string> params) { 7 log.warn("DemoServiceFallbackImpl getCateData fail"); 8 return null; 9 } 10 11 @Override 12 public ApiResponse<page<detail>> getProductData(Map<string, string> params) { 13 log.warn("DemoServiceFallbackImpl getProductData fail"); 14 return null; 15 } 16}
3、增加yml相关配置
1feign: 2 httpclient: 3 enabled: true 4 hystrix: 5 enabled: true 6hystrix: 7 command: 8 default: 9 execution: 10 timeout: 11 enabled: true 12 isolation: 13 thread: 14 timeoutInMilliseconds: 1000 //该配置需要比ribbon超时时间长 15 circuitBreaker: 16 requestVolumeThreshold: 1000 17 threadpool: 18 default: 19 coreSize: 60 20 maxQueueSize: 200 21 queueSizeRejectionThreshold: 200 22 23ribbon: 24 ReadTimeout: 500 25 ConnectTimeout: 500 26 ExecTimeout: 500 27 MaxAutoRetries: 1 //最好设置超时重试
这里如果需要查看hystrix监控,可以集成Hystrix Dashboard,详情参考 https://blog.csdn.net/u013408188/article/details/100074111
下图是我集成grafana 、prometheus的监控图 
</string,></page<detail></string,></page<object></string,string></page<detail></string,string></page<object>