Renan Lalier
Renan Lalier

Reputation: 731

How to solve Timeout FeignClient

My application is getting below error when consuming a service that performs queries in SQL Server using FeignClient.

ERROR:

Exception in thread "pool-10-thread-14" feign.RetryableException: Read timed out executing GET http://127.0.0.1:8876/processoData/search/buscaProcessoPorCliente?cliente=ELEKTRO+-+TRABALHISTA&estado=SP

My Consumer Service:

@FeignClient(url="http://127.0.0.1:8876")
public interface ProcessoConsumer {

@RequestMapping(method = RequestMethod.GET, value = "/processoData/search/buscaProcessoPorCliente?cliente={cliente}&estado={estado}")
public PagedResources<ProcessoDTO> buscaProcessoClienteEstado(@PathVariable("cliente") String cliente, @PathVariable("estado") String estado);

}

My YML:

server:
  port: 8874

endpoints:
  restart:
    enabled: true
  shutdown:
    enabled: true
  health:
    sensitive: false

eureka:
  client:
  serviceUrl:
    defaultZone: ${vcap.services.eureka-service.credentials.uri:http://xxx.xx.xxx.xx:8764}/eureka/
  instance: 
    preferIpAddress: true

ribbon:
  eureka:
    enabled: true

spring:
  application:
    name: MyApplication
  data:
    mongodb:
      host: xxx.xx.xxx.xx
      port: 27017
      uri: mongodb://xxx.xx.xxx.xx/recortesExtrator
      repositories.enabled: true
    solr:
      host: http://xxx.xx.xxx.xx:8983/solr
      repositories.enabled: true

Anyone know how to solve this?

Thanks.

Upvotes: 40

Views: 131646

Answers (10)

Evgeniy Averkin
Evgeniy Averkin

Reputation: 509

For those who use spring-cloud-starter-openfeign:

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

Upvotes: 4

Uttam Pawar
Uttam Pawar

Reputation: 154

Add the below properties to the application.properties file

value 5000 is in milliseconds

feign.client.config.default.connectTimeout: 5000
feign.client.config.default.readTimeout: 5000

Upvotes: 0

Eltan Hajiyev
Eltan Hajiyev

Reputation: 445

You can add 'Options' argument to you methods and control timeouts dynamically.

@FeignClient(url="http://127.0.0.1:8876")
public interface ProcessoConsumer {
    @RequestMapping(method = RequestMethod.GET, value = "/processoData/search/buscaProcessoPorCliente?cliente={cliente}&estado={estado}")
    PagedResources<ProcessoDTO> buscaProcessoClienteEstado(@PathVariable("cliente") String cliente, @PathVariable("estado") String estado,
                                                                  Request.Options options);
}

Use like next:

processoConsumer.buscaProcessoClienteEstado(..., new Request.Options(100, TimeUnit.MILLISECONDS,
        100, TimeUnit.MILLISECONDS, true));

Upvotes: 3

chaitanya dalvi
chaitanya dalvi

Reputation: 1669

Add the following properties into application.properties file, in milliseconds.

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

Upvotes: 55

chen
chen

Reputation: 1

Add these in the application.properties

feign.hystrix.enabled=false hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000

Upvotes: -4

yunandtidus
yunandtidus

Reputation: 4086

I'm using Feign.builder() to instantiate my Feign clients.

In order to set connectTimeout and readTimeout, I use the following :

Feign.builder()
     ...
     .options(new Request.Options(connectTimeout, readTimeout))
     .target(MyApiInterface.class, url);

Using this I can configure different timeout for different APIs.

Upvotes: 17

Kamal A. SIddiqui
Kamal A. SIddiqui

Reputation: 119

eureka: client: eureka-server-read-timeout-seconds: 30

Upvotes: -3

Sudhakar
Sudhakar

Reputation: 3180

just ran into this issue as well. As suggested by @spencergibb here is the workaround I'm using. See the link

Add these in the application.properties.

# Disable Hystrix timeout globally (for all services)
hystrix.command.default.execution.timeout.enabled: false

# Increase the Hystrix timeout to 60s (globally)
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000

Add this in the Java configuration class.

import feign.Request;

@Configuration
@EnableDiscoveryClient
@EnableFeignClients(basePackageClasses = { ServiceFeignClient.class })
@ComponentScan(basePackageClasses = { ServiceFeignClient.class })
public class FeignConfig {

    /**
     * Method to create a bean to increase the timeout value, 
     * It is used to overcome the Retryable exception while invoking the feign client.
     * @param env,
     *            An {@link ConfigurableEnvironment}
     * @return A {@link Request}
     */
    @Bean
    public static Request.Options requestOptions(ConfigurableEnvironment env) {
        int ribbonReadTimeout = env.getProperty("ribbon.ReadTimeout", int.class, 70000);
        int ribbonConnectionTimeout = env.getProperty("ribbon.ConnectTimeout", int.class, 60000);

        return new Request.Options(ribbonConnectionTimeout, ribbonReadTimeout);
    }
}

Upvotes: 9

stayfool
stayfool

Reputation: 43

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

make sure ribbon's timeout is bigger than hystrix

Upvotes: 2

Marco Tedone
Marco Tedone

Reputation: 602

Look at this answer. It did the trick for me. I also did a bit of research and I've found the properties documentation here:

https://github.com/Netflix/Hystrix/wiki/Configuration#intro

Upvotes: -2

Related Questions