My application is getting below error when consuming a service that performs queries in SQL Server using FeignClient
.
ERROR:
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
My Consumer Service:
@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);
}
My 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
Anyone know how to solve this?
Thanks.
Add below properties in Application.properties file.
feign.client.config.default.connectTimeout: 160000000
feign.client.config.default.readTimeout: 160000000
just ran into this issue as well. As suggested by @spencergibb here is the workaround I'm using. See the link
Add these in the 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
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);
}
}
I'm using Feign.builder()
to instantiate my Feign clients.
In order to set connectTimeout
and readTimeout
, I use the following :
Feign.builder()
...
.options(new Request.Options(connectTimeout, readTimeout))
.target(MyApiInterface.class, url);
Using this I can configure different timeout for different APIs.
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000
make sure ribbon's timeout is bigger than hystrix
Look at this answer. It did the trick for me. I also did a bit of research and I've found the properties documentation here:
eureka: client: eureka-server-read-timeout-seconds: 30
Add these in the application.properties
feign.hystrix.enabled=false hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
来源:https://stackoverflow.com/questions/38080283/how-to-solve-timeout-feignclient