如何设置自定义Feign客户端连接超时? [英] How to set custom Feign client connection timeout?
问题描述
我有带有Gradle依赖项的Spring Boot应用程序:
I have Spring Boot application with this Gradle dependencies:
compile("org.springframework.cloud:spring-cloud-starter-eureka")
compile("org.springframework.cloud:spring-cloud-starter-feign")
compile("org.springframework.cloud:spring-cloud-starter-ribbon")
compile("org.springframework.cloud:spring-cloud-starter-hystrix")
compile("org.springframework.cloud:spring-cloud-starter-config")
我也有Feign客户:
Also I have Feign client:
@FeignClient(name = "client")
public interface FeignService {
@RequestMapping(value = "/path", method = GET)
String response();
}
我的application.properties
:
client.ribbon.listOfServers = http://localhost:8081
ribbon.eureka.enabled=false
查询时间超过1秒时,出现异常:
When query time is more than 1 second I get exception:
com.netflix.hystrix.exception.HystrixRuntimeException: response timed-out and no fallback available.
所以我的问题是:我如何设置自定义的Feign客户端连接超时?例如2秒.
So my question is: how can I set custom Feign client connection timeout? For example to 2 seconds.
推荐答案
我使用此答案解决了我的问题: Hystrix命令失败,显示超时且没有可用的备用广告". .
I solved my problem using this answer on question: Hystrix command fails with "timed-out and no fallback available".
我在application.properties
中添加了hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=4000
以设置自定义超时.
I added hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=4000
to my application.properties
to set custom timeout.
这篇关于如何设置自定义Feign客户端连接超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!