springcloud feign集成hystrix

本章介绍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>&gt; getCateData(@RequestParam Map<string,string> params); 7 8 @GetMapping("/v1/api/getProductData") 9 ApiResponse<page<detail>&gt; 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>&gt; getCateData (Map<string, string> params) { 7 log.warn("DemoServiceFallbackImpl getCateData fail"); 8 return null; 9 } 10 11 @Override 12 public ApiResponse<page<detail>&gt; 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>

点赞
收藏

评论区

加载中...

相关推荐

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

springboot接入微信app支付

一:集成步骤1.引入依赖:<dependency<groupIdcom.github.wxpay</groupId<artifactIdwxpaysdk</artifactId<version0.0.3</version</dependency

springcloud(八) Hystrix监控

一、Feign项目Hystrix自带的监控  在feign项目pom.xml添加:<!1,使用Hystrix的模块hystrixmetricseventstream,就可将这些监控的指标信息以text/eventstream的格式暴露给外部系统。spring

springcloud微服务config的使用

首先需要建立一个server端:pom依赖中加入<dependency<groupIdorg.springframework.cloud</groupId<artifactIdspringcloudconfigserver</artifactId</dependency

SpringBoot1.0版本2.0版本配置redis

pom依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarterdataredis</artifactId</dependency<

Springboot简单集成ActiveMQ

Springboot简单集成ActiveMQ消息发送者的实现pom.xml添加依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarteractivemq</artifactId</dependency<d