第一步引入相关依赖

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

第二步 在yml中开启重试机制

spring:
cloud:
loadbalancer:
retry:
enabled: true

第三步 启动类中开启熔断的注解,然后在yaml中设置断路器超时时间等

@EnableCircuitBreaker
在这里插入图片描述

# 断路器的超时时间需要大于Ribbon的超时时间,不然不会触发重试。
hystrix:
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 6000
ribbon:
# 请求连接超时时间
ConnectTimeout: 3000
# 请求处理的超时时间
ReadTimeout: 3000
# 对所有操作请求都进行重试
OkToRetryOnAllOperations: true
# 对当前实例的重试次数
maxAutoRetries: 3
# 切换实例的重试次数
# MaxAutoRetriesNextServer: 2

关注我的公众号SpaceObj 领取idea系列激活码

posted on   张伯灵  阅读(613)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)



点击右上角即可分享
微信分享提示