Can't configure Feign Client timeouts

 ̄綄美尐妖づ 提交于 2020-02-02 14:57:49

问题


I'm using Feign Client with disabled Load Balancer

@FeignClient(name = "my-client", url = "${myHost}", configuration = ClientContext.class)

So, all ribbon properties are ignored. I'm trying to set custom timeouts by different ways, but Feign ignores all them and throws TimeoutException after 60 seconds. Ways I tried to use: in ClientContext: 1)

@Value("${feign.connectTimeout:10000}")
private int connectTimeout;

@Value("${feign.readTimeOut:300000}")
private int readTimeout;

@Bean
public Request.Options options() {
    return new Request.Options(connectTimeout, readTimeout);
}

2)

@Bean
public Request.Options options() {
    return new Request.Options(10_000, 300_000);
}

in bootstrap.properties file: 1)

feign.client.default.connect-timeout=10000
feign.client.default.read-timeout=300000

2)

feign.client.default.config.connect-timeout=10000
feign.client.default.config.read-timeout=300000

3)

feign.client.default.connectTimeout=10000
feign.client.default.readTimeout=300000

4)

feign.client.default.config.connectTimeout=10000
feign.client.default.config.readTimeout=300000

Error stack trace is:

Error Message: feign.RetryableException: Read timed out executing GET http://myrequest...
Stacktrace: 
feign.FeignException.errorExecuting(FeignException.java:67)
feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:10)
feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)

Can you suggest me right configuration or found what is wrong in code blocks above?


回答1:


The right solution was

@Value("${feign.connectTimeout:10000}")
private int connectTimeout;

@Value("${feign.readTimeOut:300000}")
private int readTimeout;

@Bean
public Request.Options options() {
    return new Request.Options(connectTimeout, readTimeout);
}

and add to .properties file this one payer-service-client.feign.hystrix.enabled=false




回答2:


There is also a way to do this with configuration only.

Add to your application.yml:

feign:
  client:
    config:
      my-client:
        connectTimeout: 10000
        readTimeout: 300000


来源:https://stackoverflow.com/questions/46526431/cant-configure-feign-client-timeouts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!