2016-06-28 372 views
1

当使用FeignClient使用在SQL Server中执行查询的服务时,我的应用程序正在收到错误。如何解决超时FeignClient

错误:

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

我的消费服务:

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

} 

我阳明:

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 

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

感谢。

+0

嘿雷南,之后你会得到一个超时错误和多久到后端的呼叫通常需要? –

+0

为什么你的费恩客户说端口8876,但你的YML配置说端口8874? – psantamaria

回答

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

确保色带的超时比椎

+0

反之亦然: “使用包装Ribbon客户端的Hystrix命令时,如果希望确保Hystrix超时配置为超过配置的功能区超时(包括可能发生的任何潜在重试次数),例如if您的功能区连接超时时间为1秒,并且功能区客户端可能会重试该请求三次,而您的Hystrix超时应稍微超过三秒。“ https://cloud.spring.io/spring-cloud-netflix/single/spring-cloud-netflix.html#_hystrix_timeouts_and_ribbon_clients –

0

恰好碰到了这个问题,也是更大的。正如@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); 
    } 
} 
-1

在application.properties添加这些

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

相关问题