How to solve Timeout FeignClient

空扰寡人 提交于 2019-12-05 14:57:39

问题


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.


回答1:


Add below properties in Application.properties file.

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



回答2:


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);
    }
}



回答3:


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.




回答4:


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

make sure ribbon's timeout is bigger than hystrix




回答5:


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




回答6:


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




回答7:


Add these in the application.properties

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



来源:https://stackoverflow.com/questions/38080283/how-to-solve-timeout-feignclient

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