首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenFeign + Hystrix -不同客户端的不同超时

OpenFeign + Hystrix -不同客户端的不同超时
EN

Stack Overflow用户
提问于 2021-02-24 17:03:20
回答 2查看 849关注 0票数 2

在我的Spring应用程序中,我有一个冒充的Hystrix工作。

我已经将Hystrix的默认超时设置为10000 to,如下所示:

代码语言:javascript
复制
feign:
  hystrix:
    enabled: true

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 10000

问题是,我有一个客户,让我们称之为HeavyClient,这是一个沉重的调用,有时需要更多的时间,并导致电路中断。,我想增加超时值上限,只为这一个人。有可能吗?

我试过一些假冒伪劣的东西,比如:

代码语言:javascript
复制
feign:
  client:
    config:
      HeavyClient:
        connectTimeout: 30000
        readTimeout: 30000

但这不管用。我想Hystrix不会检查冒牌货。

我在用:

代码语言:javascript
复制
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

任何帮助都是感激的,谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-03-04 17:22:43

在that上进行了更深入的搜索之后,我在这个GitHub问题上发现,默认的Hystrix命令命名类似于InterfaceName#methodNameSignature()

因此,例如,给定以下@FeignClient

代码语言:javascript
复制
@FeignClient(name = "heavyClient", url = "${heavyclient.url}")
public interface HeavyClient {
    
    @RequestMapping("/process/{operation}")
    public ResponseEntity<Response> process(@PathVariable("operation") String operation);
    
}

它将被配置为:

代码语言:javascript
复制
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 5000
    HeavyClient#process(String):
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 30000

不幸的是,这对我没有用.不知道为什么..。因此,为了解决这个问题,我注册了一个SetterFactory类型的bean,它将创建给定@FeignClient名称的命令键:

代码语言:javascript
复制
    @Bean
    public SetterFactory setterFactory() {
        return (target, method) -> HystrixCommand.Setter
                .withGroupKey(HystrixCommandGroupKey.Factory.asKey(target.name()))
                .andCommandKey(HystrixCommandKey.Factory.asKey(target.name()));
    }

然后,我可以简单地使用以下配置:

代码语言:javascript
复制
hystrix:
  command:
    heavyClient:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 30000
票数 0
EN

Stack Overflow用户

发布于 2022-02-24 11:48:52

CircuitBreakerNameResolver将电路命名为HystrixCommandKey,有一个默认的实现DefaultCircuitBreakerNameResolver,它的输出键模式是HardCodedTarget#methodName(ParamClass),所以您可以定制CircuitBreakerNameResolver而不是DefaultCircuitBreakerNameResolver

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66355496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档