Spring Cloud服务熔断,降级

一、服务熔断

@HystrixCommand注解

name="circuitBreaker.enabled",value="true"
name="circuitBreaker.requestVolumeThreshold",value="10" // 设置在一个滚动窗口中,打开断路器的最少请求数
name="circuitBreaker.sleepWindowInMilliseconds",value="10000" // 设置在回路被打开,拒绝请求到再次尝试请求并决定回路是否继续打开的时间
name="circuitBreaker.errorThresholdPercentage",value="60" // 错误率达到60%触发降级
参考: https://www.jianshu.com/p/397...

配置

hystrix:
    command: 
        default: // 默认是所有方法
            execution:
                isolation:
                    thread: 
                        timeoutInMilliseconds: 2000
        getProductInfoList: // 为指定方法设置超时时间
            execution:
                isolation:
                    thread: 
                        timeoutInMilliseconds: 3000
feign: // feign-hystrix
    hystrix:
        enabled: true
logging:
    level:
        org.springframework.cloud.netflix.feign: debug // 日志级别调整
                        

依赖


    org.springframework.cloud
    spring-cloud-starter-hytrsix


    org.springframework.cloud
    spring-cloud-starter-hytrsix-dashboard-
    // 需要在启动类上加注解:@EnabledHystrixDashboard

你可能感兴趣的:(微服务,java)