微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 如何设置自定义Feign客户端连接超时?

我有这个Gradle依赖项的 Spring Boot应用程序:
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客户端:

@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秒时,我得到异常:

com.netflix.hystrix.exception.HystrixRuntimeException: response timed-out and no fallback available.

所以我的问题是:如何设置自定义Feign客户端连接超时?例如2秒.

解决方法

我使用 answer问题解决了我的问题: Hystrix command fails with “timed-out and no fallback available”.

我将hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 4000添加到我的application.properties以设置自定义超时.

原文地址:https://www.jb51.cc/java/128094.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐