3

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?

gad_gadskiy
  • 160
  • 1
  • 11

3 Answers3

5

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

gad_gadskiy
  • 160
  • 1
  • 11
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
Amit Goldstein
  • 827
  • 9
  • 18
0

I think you are misplacing the default attribute.

The correct way of using the default timeout properties are :

feign.client.config.default.connectTimeout=xxxx
feign.client.config.default.readTimeout=xxxx

These will be applicable for all the feign clients. If you want to apply it to a specific client you can refer to the other answers.