gad_gadskiy
gad_gadskiy

Reputation: 220

Can't configure Feign Client timeouts

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?

Upvotes: 5

Views: 12125

Answers (5)

Xelian
Xelian

Reputation: 17198

For open-feign you need

 spring:
  cloud:
    openfeign:
      client:
        config:
          default:
            readTimeout: 5000
            connectTimeout: 5000

Upvotes: 3

ddotsdot
ddotsdot

Reputation: 303

According to this answer you need to put only

spring.cloud.openfeign.client.config.default.readTimeout=300000 spring.cloud.openfeign.client.config.default.connect-timeout=10000

in your application.properties

Upvotes: 2

user4773260
user4773260

Reputation:

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.

Upvotes: 1

Amit Goldstein
Amit Goldstein

Reputation: 907

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

Upvotes: 2

gad_gadskiy
gad_gadskiy

Reputation: 220

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

Upvotes: 5

Related Questions