Feign Hystrix (HystrixCommonKey) 设置单独接口的超时时间和FallBack

it2022-05-07  11

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  来源:  原文:https://blog.csdn.net/qq_30257149/article/details/86512197  版权声明:本文为博主原创文章,转载请附上博文链接!


最新回复(0)