java – 如何设置自定义Feign客户端连接超时?
发布时间:2020-12-15 02:53:01 所属栏目:Java 来源:网络整理
导读:我有这个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")com
我有这个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以设置自定义超时. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |