如何解决Timeout FeignClient

Ren*_*ier 12 java spring-data spring-boot netflix-feign

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

错误:

线程"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);

}
Run Code Online (Sandbox Code Playgroud)

我的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
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

谢谢.

cha*_*lvi 18

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

feign.client.config.default.connectTimeout: 160000000
feign.client.config.default.readTimeout: 160000000
Run Code Online (Sandbox Code Playgroud)

  • 问题是两者都需要设置才能生效。‍♂️ 这是相关的[来源](https://github.com/spring-cloud/spring-cloud-openfeign/blob/21a2a59461f95fc1c78bd26a6f55187cc576c617/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud /openfeign/FeignClientFactoryBean.java#L171) (8认同)
  • 我尝试了同样的问题,仅在设置这两个属性后才修复超时。另外一个提示,您可以为不同的 API 配置不同的超时,替换 API feignName 的 _default_ 单词,如[此处](https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-feign. html#spring-cloud-feign-overriding-defaults) (3认同)
  • 在尝试了各种包含 Hystrix、ribbon 等属性的黑魔法之后,这是我遇到的最干净(且有效)的解决方案。 (2认同)

yun*_*dus 9

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

为了设置connectTimeoutand readTimeout,我使用以下内容:

Feign.builder()
     ...
     .options(new Request.Options(connectTimeout, readTimeout))
     .target(MyApiInterface.class, url);
Run Code Online (Sandbox Code Playgroud)

使用它我可以为不同的 API 配置不同的超时。

  • 此 .options 现已弃用,最好使用新的 .options(new Request.Options(CONNECTION_TIME_OUT_IN_SEC, TimeUnit.SECONDS,CONNECTION_TIME_OUT_IN_SEC, TimeUnit.Seconds, true))。最后一个参数用于 followRedirects。您可以根据提供的单位给出任何超时值。 (3认同)

Sud*_*kar 7

刚刚也遇到了这个问题。正如@spencergibb 所建议的,这里是我正在使用的解决方法。见链接

在 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
Run Code Online (Sandbox Code Playgroud)

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);
    }
}
Run Code Online (Sandbox Code Playgroud)


Mar*_*one -2

看看这个答案。它对我有用。我还做了一些研究,在这里找到了属性文档:

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