springcloud feign集成hystrix

Easter79
• 阅读 616

本章介绍feign集成hystrix 1、增加pom依赖`

        <dependency>
            <groupid>org.springframework.cloud</groupid>
            <artifactid>spring-cloud-starter-netflix-hystrix</artifactid>
        </dependency>

2、启动类中增加注解@EnableHystrix

3、增加feign接口fallback以及相关配置

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>&gt; getCateData(@RequestParam Map<string,string> params);

    @GetMapping("/v1/api/getProductData")
    ApiResponse<page<detail>&gt; getProductData(@RequestParam Map<string,string> params);
}

DemoServiceFallbackImpl

@Slf4j
@Component
public class DemoServiceFallbackImpl implements DemoService {

    @Override
    public ApiResponse<page<object>&gt; getCateData (Map<string, string> params) {
        log.warn("DemoServiceFallbackImpl getCateData fail");
        return null;
    }

    @Override
    public ApiResponse<page<detail>&gt; getProductData(Map<string, string> params) {
        log.warn("DemoServiceFallbackImpl getProductData fail");
        return null;
    }
}

3、增加yml相关配置

feign:
  httpclient:
    enabled: true
  hystrix:
    enabled: true
hystrix:
  command:
    default:
      execution:
        timeout:
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 1000 //该配置需要比ribbon超时时间长
      circuitBreaker:
        requestVolumeThreshold: 1000
  threadpool:
    default:
      coreSize: 60
      maxQueueSize: 200
      queueSizeRejectionThreshold: 200

ribbon:
  ReadTimeout: 500
  ConnectTimeout: 500
  ExecTimeout: 500
  MaxAutoRetries: 1 //最好设置超时重试

这里如果需要查看hystrix监控,可以集成Hystrix Dashboard,详情参考 https://blog.csdn.net/u013408188/article/details/100074111

下图是我集成grafana 、prometheus的监控图 springcloud feign集成hystrix springcloud feign集成hystrix </string,></page</string,></page</string,string></page</string,string></page

点赞
收藏
评论区
推荐文章
Easter79 Easter79
2年前
springcloud(八) Hystrix监控
一、Feign项目Hystrix自带的监控  在feign项目pom.xml添加:<!1,使用Hystrix的模块hystrixmetricseventstream,就可将这些监控的指标信息以text/eventstream的格式暴露给外部系统。spring
Easter79 Easter79
2年前
springboot接入微信app支付
一:集成步骤1.引入依赖:<dependency<groupIdcom.github.wxpay</groupId<artifactIdwxpaysdk</artifactId<version0.0.3</version</dependency
Easter79 Easter79
2年前
springcloud微服务config的使用
首先需要建立一个server端:pom依赖中加入<dependency<groupIdorg.springframework.cloud</groupId<artifactIdspringcloudconfigserver</artifactId</dependency
Easter79 Easter79
2年前
SpringBoot1.0版本2.0版本配置redis
pom依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarterdataredis</artifactId</dependency<
Easter79 Easter79
2年前
Springboot简单集成ActiveMQ
Springboot简单集成ActiveMQ消息发送者的实现pom.xml添加依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarteractivemq</artifactId</dependency<d
Stella981 Stella981
2年前
SpringBoot1.0版本2.0版本配置redis
pom依赖<dependency<groupIdorg.springframework.boot</groupId<artifactIdspringbootstarterdataredis</artifactId</dependency<
Stella981 Stella981
2年前
Service Discovery with Spring Cloud Eureka
<dependency<groupIdorg.springframework.cloud</groupId<artifactIdspringcloudstartereurekaserver</artifactId</dependency@SpringBootApplication@EnableEurekaServe
Wesley13 Wesley13
2年前
spring cloud
添加熔断依赖<dependency<groupIdorg.springframework.cloud</groupId<artifactIdspringcloudstarternetflixhystrix</artifactId</dependencya
Easter79 Easter79
2年前
SpringCloud(第 016 篇)电影微服务,定制Feign,一个Feign功能禁用Hystrix,另一个Feign功能启用Hystrix
SpringCloud(第016篇)电影微服务,定制Feign,一个Feign功能禁用Hystrix,另一个Feign功能启用Hystrix一、大致介绍1、在一些场景中,部分功能需
Stella981 Stella981
2年前
ElasticSearch Java API 增删改查操作
1.添加pom.xml依赖<dependency<groupIdjunit</groupId<artifactIdjunit</artifactId<version4.11</version<scopetest</scope</dependency<dependency<groupI
Easter79
Easter79
Lv1
今生可爱与温柔,每一样都不能少。
文章
2.8k
粉丝
5
获赞
1.2k