如何解决Timeout FeignClient

时间:2016-06-28 15:23:49

标签: java spring-boot spring-data netflix-feign

使用FeignClient使用在SQL Server中执行查询的服务时,我的应用程序遇到以下错误。

错误:

  

线程中的异常“pool-10-thread-14”feign.RetryableException:读取超时执行GET   http://127.0.0.1:8876/processoData/search/buscaProcessoPorCliente?cliente=ELEKTRO+-+TRABALHISTA&estado=SP

我的消费者服务:

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

}

我的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

任何人都知道如何解决这个问题?

感谢。

7 个答案:

答案 0 :(得分:10)

在Application.properties文件中添加以下属性。

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

答案 1 :(得分:2)

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

确保功能区的超时时间大于hystrix

答案 2 :(得分:2)

也遇到了这个问题。正如@spencergibb所建议的那样,我正在使用的解决方法。请参阅link

在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

在Java配置类中添加它。

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 :(得分:0)

看看这个answer。它为我做了伎俩。我也做了一些研究,我在这里找到了属性文档:

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

答案 4 :(得分:0)

我正在使用Feign.builder()实例化我的Feign客户。

为了设置connectTimeoutreadTimeout,我使用以下命令:

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

借此,我可以为不同的API配置不同的超时时间。

答案 5 :(得分:-1)

尤里卡:   客户:     eureka-服务器读取超时秒数:30

答案 6 :(得分:-3)

在application.properties

中添加这些内容
  

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