天天看点

微服务 断路器配置

hystrix 参数配置详解

特别说明支持对feign的熔断配置

一、注解时的使用方式

@HystrixCommand(commandKey = "bankgatewaytest",//HystrixCommandKey
threadPoolKey = "payServiceThreadKey",
        fallbackMethod = "callPayServiceFallback",
        threadPoolProperties = {
                @HystrixProperty(name = "coreSize", value = "100"),//线程池大小
                @HystrixProperty(name = "maxQueueSize", value = "100"),//最大排队长度
                @HystrixProperty(name = "queueSizeRejectionThreshold", value = "10")//排队线程数量阈值,默认为5,达到时拒绝
        },
        commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000"),//断路器的超时时间默认1000毫秒
                @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),//熔断触发的最小个数/10s  默认值:20
                @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "10000"),//熔断多少秒后去尝试请求  默认值:5000
                @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "60"),//失败率达到多少百分比后熔断 默认值:50 主要根据依赖重要性进行调整
        })
           

二、配置文件的使用方式:

1、配置默认的断路器

#断路器的超时时间默认1000毫秒
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=10000
#熔断触发的最小个数/10s  默认值:20
hystrix.command.default.circuitBreaker.requestVolumeThreshold=10
#熔断多少秒后去尝试请求  默认值:5000
hystrix.command.default.circuitBreaker.sleepWindowInMilliseconds=10000
#失败率达到多少百分比后熔断 默认值:50 主要根据依赖重要性进行调整
hystrix.command.default.circuitBreaker.errorThresholdPercentage=60

#并发执行的最大线程数,默认10
hystrix.threadpool.default.coreSize=100
#线程池中最大排队长度,即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝。
hystrix.threadpool.default.maxQueueSize=100
#排队线程数量阈值,默认为5,达到时拒绝
hystrix.threadpool.default.queueSizeRejectionThreshold=10

2、根据commandKey 配置特定的断路器,默认为方法名
hystrix.command.bankgatewaytest.execution.isolation.thread.timeoutInMilliseconds=10000
#并发执行的最大线程数,默认10
hystrix.threadpool.payServiceThreadKey.coreSize=100

3、根据FeignClient 配置特定的断路器,默认为;类名+方法名+参数类型
hystrix.command.YcdFeign#vehicleAndModel(YcdVehicleAndModelReq).execution.isolation.thread.timeoutInMilliseconds=10000
#并发执行的最大线程数,默认10,   线程名为value值
hystrix.threadpool.ycd.coreSize=100
           

继续阅读