1.描述
Feign接口调用注册中心服务,一般默认超时时间为:1秒,超过一秒钟会超时报错
熔断超时时间,默认也是1秒
2. 更改默认超时时间(开启Feign熔断)
更改配置文件:application.yml
添加注解
配置代码:
feign:
hystrix:
enabled: true #开启Feign的熔断功能
client:
config:
default:
connectTimeout: 5000 #连接超时时间2秒
readTimeout: 5000 #读超时时间2秒
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 10000 #设置熔断时间10秒
依赖:
<!-- 熔断-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
本文介绍了如何修改Feign的默认超时时间以及开启熔断功能,通过配置`application.yml`文件,设置连接超时、读取超时和熔断时间,确保服务的稳定性和容错性。同时引入了Hystrix依赖来实现熔断。



6万+

被折叠的 条评论
为什么被折叠?



