28

使用在 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);

}

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

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

谢谢。

4

7 回答 7

46

将以下属性添加到application.properties文件中,以毫秒为单位。

feign.client.config.default.connectTimeout=160000000
feign.client.config.default.readTimeout=160000000
于 2018-10-09T07:16:49.193 回答
10

Feign.builder()用来实例化我的 Feign 客户。

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

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

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

于 2019-04-29T08:41:09.783 回答
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

在 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);
    }
}
于 2017-07-05T17:10:51.307 回答
2
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

确保功能区的超时大于 hystrix

于 2017-07-05T06:17:42.580 回答
-2

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

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

于 2017-01-11T06:55:35.613 回答
-3

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

于 2019-01-29T13:52:46.723 回答
-4

在 application.properties 中添加这些

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

于 2017-08-08T08:40:58.567 回答