Feign設置單獨接口的超時時間和FallBack(HystrixCommonKey)
HystrixCommonKey生成方法:類名#方法名(入參類型)
? final class Default implements SetterFactory {
?
? ? @Override
? ? public HystrixCommand.Setter create(Target<?> target, Method method) {
? ? ? String groupKey = target.name();
? ? ? // 在這里生產HystrixCommonKey
? ? ? String commandKey = Feign.configKey(target.type(), method);
? ? ? return HystrixCommand.Setter
? ? ? ? ? .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
? ? ? ? ? .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
? ? }
? }
配置如下:
?
hystrix:
? threadpool:
? ? default:
? ? ? # 核心線程池大小 ?默認10
? ? ? coreSize: 20
? ? ? # 最大最大線程池大小
? ? ? maximumSize: 30
? ? ? # 此屬性允許maximumSize的配置生效。 那么該值可以等于或高于coreSize。 設置coreSize <maximumSize會創建一個線程池,該線程池可以支持maximumSize并發,但在相對不活動期間將向系統返回線程。 (以keepAliveTimeInMinutes為準)
? ? ? allowMaximumSizeToDivergeFromCoreSize: true
? ? ? # 請求等待隊列
? ? ? maxQueueSize: 10
? ? ? # 隊列大小拒絕閥值 在還未超過請求等待隊列時也會拒絕的大小
? ? ? queueSizeRejectionThreshold: 10
? command:
? ? LimitCheckApi#rcsLimitCheck(RpcRequest): ?#default全局有效 默認值為 commonKey commonKey生成方法在 Feign.configKey(target.type(), method) 中
? ? ? fallback:
? ? ? ? enabled: true
? ? ? execution:
? ? ? ? timeout:
? ? ? ? ? #如果enabled設置為false,則請求超時交給ribbon控制,為true,則超時作為熔斷根據
? ? ? ? ? enabled: true
? ? ? ? isolation:
? ? ? ? ? #隔離策略,有THREAD和SEMAPHORE
? ? ? ? ? #THREAD - 它在單獨的線程上執行,并發請求受線程池中的線程數量的限制
? ? ? ? ? #SEMAPHORE - 它在調用線程上執行,并發請求受到信號量計數的限制
? ? ? ? ? #對比:https://www.cnblogs.com/java-synchronized/p/7927726.html
? ? ? ? ? thread:
? ? ? ? ? ? timeoutInMilliseconds: 800 #斷路器超時時間,默認1000ms
? ? LimitCheckApi#testTimeOutFallBack(long):
? ? ? fallback:
? ? ? ? enabled: true
? ? ? execution:
? ? ? ? timeout:
? ? ? ? ? ? #如果enabled設置為false,則請求超時交給ribbon控制,為true,則超時作為熔斷根據
? ? ? ? ? ? enabled: true
? ? ? ? isolation:
? ? ? ? ? #隔離策略,有THREAD和SEMAPHORE
? ? ? ? ? #THREAD - 它在單獨的線程上執行,并發請求受線程池中的線程數量的限制
? ? ? ? ? #SEMAPHORE - 它在調用線程上執行,并發請求受到信號量計數的限制
? ? ? ? ? #對比:https://www.cnblogs.com/java-synchronized/p/7927726.html
? ? ? ? ? thread:
? ? ? ? ? ? timeoutInMilliseconds: 800 #斷路器超時時間,默認1000ms
?
feign:
? hystrix:
? ? enabled: true
---------------------?
作者:lantao_csdn?
來源:CSDN?
原文:https://blog.csdn.net/qq_30257149/article/details/86512197?
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!