zoukankan      html  css  js  c++  java
  • springcloud中feign声明式服务和hystrix请求熔断和服务降级

    一、配置

    pom文件引入依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>

    启动类配置

    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableFeignClients
    @EnableCircuitBreaker
    public class StartCloudFeignApplication {
        public static void main(String[] args) {
            SpringApplication.run(StartCloudFeignApplication.class,args);
        }
    }

    feign常用配置

    feign:
      hystrix:
        enabled: true #在Feign中开启Hystrix
      compression:
        request:
          enabled: false #是否对请求进行GZIP压缩
          mime-types: text/xml,application/xml,application/json #指定压缩的请求数据类型
          min-request-size: 2048 #超过该大小的请求会被压缩
        response:
          enabled: false #是否对响应进行GZIP压缩

    hystrix:
      command:
    default: #default全局有效,service id指定应用有效
    execution:
    timeout:
    enabled: false
    isolation:
    thread:
    timeoutInMilliseconds: 3000 #断路器超时时间,默认1000ms

     二、服务降级示例

    @FeignClient(name = "cloud-web1",fallback = CloudWebHystrixImpl.class)
    public interface ICloudWebFeign {
        @GetMapping("/test1")
        public String test1();
    }
    @Component
    public class CloudWebHystrixImpl implements ICloudWebFeign {
        @Override
        public String test1() {
            return "调用失败,服务降级";
        }
    }
  • 相关阅读:
    tophat安装
    glimmer 3.02安装小记
    Augustus安装小记
    推荐几个手机网站在线预览测试工具
    软件分辨率兼容性测试
    谈谈软件兼容性测试
    网页兼容性测试(工具使用IETESTER、Firefox、360安全浏览器)
    12款很棒的浏览器兼容性测试工具推荐
    测试用例设计——如何提高测试覆盖率
    软件测试报告写作实战案例
  • 原文地址:https://www.cnblogs.com/mufeng07/p/12869645.html
Copyright © 2011-2022 走看看