<dependency>
<groupId>org.springframework.cloudgroupId>
<artifactId>spring-cloud-starter-netflix-hystrixartifactId>
dependency>
feign:
hystrix:
enabled: true #开启Hystrix对Feign的支持
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-fih500vY-1658333048282)(/Users/guotengjiang/Library/Application Support/typora-user-images/image-20220719175326718.png)]](https://1000bd.com/contentImg/2022/07/27/001410365.png)

hystrix:
...
command:
default:
...
circuitBreaker: #熔断器相关配置
enabled: true #是否使用熔断器,默认为true
requestVolumeThreshold: 20 #窗口时间内的最小请求数
sleepWindowInMilliseconds: 5000 #打开后允许一次尝试的睡眠时间,默认配置为5秒
errorThresholdPercentage: 50 #窗口时间内熔断器开启的错误比例,默认配置为50
metrics:
rollingStats:
timeInMilliseconds: 10000 #滑动窗口时间
numBuckets: 10 #滑动窗口的时间桶数
hystrix.command.类名#方法名(参数类型列表)
hystrix:
...
command:
UserClient#detail(Long): #格式为:类名#方法名(参数类型列表)
...
circuitBreaker: #熔断器相关配置
enabled: true #是否使用熔断器,默认为true
requestVolumeThreshold: 20 #至少有20个请求,熔断器才会达到熔断触发的次数阈值
sleepWindowInMilliseconds: 5000 #打开后允许一次尝试的睡眠时间,默认配置为5秒
errorThresholdPercentage: 50 #窗口时间内熔断器开启的错误比例,默认配置为50
metrics:
rollingPercentile:
timeInMilliseconds: 60000 #滑动窗口时间
numBuckets: 600 #滑动窗口的时间桶数
bucketSize: 200 #时间桶内的统计次数