Feign Hystrix (HystrixCommonKey) 设置单独接口的超时时间和FallBack
Feign設(shè)置單獨(dú)接口的超時(shí)時(shí)間和FallBack(HystrixCommonKey)
HystrixCommonKey生成方法:類名#方法名(入?yún)㈩愋?
? final class Default implements SetterFactory {
?
? ? @Override
? ? public HystrixCommand.Setter create(Target<?> target, Method method) {
? ? ? String groupKey = target.name();
? ? ? // 在這里生產(chǎn)HystrixCommonKey
? ? ? String commandKey = Feign.configKey(target.type(), method);
? ? ? return HystrixCommand.Setter
? ? ? ? ? .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
? ? ? ? ? .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
? ? }
? }
配置如下:
?
hystrix:
? threadpool:
? ? default:
? ? ? # 核心線程池大小 ?默認(rèn)10
? ? ? coreSize: 20
? ? ? # 最大最大線程池大小
? ? ? maximumSize: 30
? ? ? # 此屬性允許maximumSize的配置生效。 那么該值可以等于或高于coreSize。 設(shè)置coreSize <maximumSize會(huì)創(chuàng)建一個(gè)線程池,該線程池可以支持maximumSize并發(fā),但在相對(duì)不活動(dòng)期間將向系統(tǒng)返回線程。 (以keepAliveTimeInMinutes為準(zhǔn))
? ? ? allowMaximumSizeToDivergeFromCoreSize: true
? ? ? # 請(qǐng)求等待隊(duì)列
? ? ? maxQueueSize: 10
? ? ? # 隊(duì)列大小拒絕閥值 在還未超過請(qǐng)求等待隊(duì)列時(shí)也會(huì)拒絕的大小
? ? ? queueSizeRejectionThreshold: 10
? command:
? ? LimitCheckApi#rcsLimitCheck(RpcRequest): ?#default全局有效 默認(rèn)值為 commonKey commonKey生成方法在 Feign.configKey(target.type(), method) 中
? ? ? fallback:
? ? ? ? enabled: true
? ? ? execution:
? ? ? ? timeout:
? ? ? ? ? #如果enabled設(shè)置為false,則請(qǐng)求超時(shí)交給ribbon控制,為true,則超時(shí)作為熔斷根據(jù)
? ? ? ? ? enabled: true
? ? ? ? isolation:
? ? ? ? ? #隔離策略,有THREAD和SEMAPHORE
? ? ? ? ? #THREAD - 它在單獨(dú)的線程上執(zhí)行,并發(fā)請(qǐng)求受線程池中的線程數(shù)量的限制
? ? ? ? ? #SEMAPHORE - 它在調(diào)用線程上執(zhí)行,并發(fā)請(qǐng)求受到信號(hào)量計(jì)數(shù)的限制
? ? ? ? ? #對(duì)比:https://www.cnblogs.com/java-synchronized/p/7927726.html
? ? ? ? ? thread:
? ? ? ? ? ? timeoutInMilliseconds: 800 #斷路器超時(shí)時(shí)間,默認(rèn)1000ms
? ? LimitCheckApi#testTimeOutFallBack(long):
? ? ? fallback:
? ? ? ? enabled: true
? ? ? execution:
? ? ? ? timeout:
? ? ? ? ? ? #如果enabled設(shè)置為false,則請(qǐng)求超時(shí)交給ribbon控制,為true,則超時(shí)作為熔斷根據(jù)
? ? ? ? ? ? enabled: true
? ? ? ? isolation:
? ? ? ? ? #隔離策略,有THREAD和SEMAPHORE
? ? ? ? ? #THREAD - 它在單獨(dú)的線程上執(zhí)行,并發(fā)請(qǐng)求受線程池中的線程數(shù)量的限制
? ? ? ? ? #SEMAPHORE - 它在調(diào)用線程上執(zhí)行,并發(fā)請(qǐng)求受到信號(hào)量計(jì)數(shù)的限制
? ? ? ? ? #對(duì)比:https://www.cnblogs.com/java-synchronized/p/7927726.html
? ? ? ? ? thread:
? ? ? ? ? ? timeoutInMilliseconds: 800 #斷路器超時(shí)時(shí)間,默認(rèn)1000ms
?
feign:
? hystrix:
? ? enabled: true
---------------------?
作者:lantao_csdn?
來源:CSDN?
原文:https://blog.csdn.net/qq_30257149/article/details/86512197?
版權(quán)聲明:本文為博主原創(chuàng)文章,轉(zhuǎn)載請(qǐng)附上博文鏈接!
總結(jié)
以上是生活随笔為你收集整理的Feign Hystrix (HystrixCommonKey) 设置单独接口的超时时间和FallBack的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle--导出、导入blob类型的
- 下一篇: MAC配置JCO,与找不到sapjco3