How to set custom Feign client connection timeout?

流过昼夜 提交于 2020-04-07 14:20:34

问题


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")

Also I have Feign client:

@FeignClient(name = "client")
public interface FeignService {

    @RequestMapping(value = "/path", method = GET)
    String response();

}

My application.properties:

client.ribbon.listOfServers = http://localhost:8081
ribbon.eureka.enabled=false

When query time is more than 1 second I get exception:

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

So my question is: how can I set custom Feign client connection timeout? For example to 2 seconds.


回答1:


I solved my problem using this answer on question: Hystrix command fails with “timed-out and no fallback available”.

I added hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=4000 to my application.properties to set custom timeout.



来源:https://stackoverflow.com/questions/41470321/how-to-set-custom-feign-client-connection-timeout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!