簡體   English   中英

FeignClient超時如何解決

[英]How to solve Timeout FeignClient

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

有誰知道如何解決這個問題?

謝謝。

將以下屬性添加到application.properties文件中,以毫秒為單位。

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

我正在使用Feign.builder()來實例化我的 Feign 客戶端。

為了設置connectTimeoutreadTimeout ,我使用以下內容:

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

使用它,我可以為不同的 API 配置不同的超時。

剛剛也遇到了這個問題。 正如@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);
    }
}
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

確保功能區的超時大於 hystrix

您可以為您的方法添加“選項”參數並動態控制超時。

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

使用如下:

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

將以下屬性添加到 application.properties 文件

值 5000 以毫秒為單位

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

看看這個答案 它對我有用。 我也做了一些研究,在這里找到了屬性文檔:

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

尤里卡:客戶端:尤里卡服務器讀取超時秒數:30

在 application.properties 中添加這些

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM