天天看點

微服務 斷路器配置

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
           

繼續閱讀