Circuit Breaker Properties Configuration
您可以在应用的配置属性文件中配置 CircuitBreaker
和 TimeLimiter
配置或实例。属性配置的优先级高于 Java Customizer
配置。
优先级从高到低依次下降。
-
方法 (ID) 配置 — 针对特定方法或操作
-
服务 (组) 配置 — 针对特定的应用程序服务或操作
-
Global default config
ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName)
Resilience4JCircuitBreakerFactory.create(String id, String groupName)
Global Default Properties Configuration
resilience4j.circuitbreaker:
configs:
default:
registerHealthIndicator: true
slidingWindowSize: 50
resilience4j.timelimiter:
configs:
default:
timeoutDuration: 5s
cancelRunningFuture: true
Configs Properties Configuration
resilience4j.circuitbreaker:
configs:
groupA:
registerHealthIndicator: true
slidingWindowSize: 200
resilience4j.timelimiter:
configs:
groupC:
timeoutDuration: 3s
cancelRunningFuture: true
Instances Properties Configuration
resilience4j.circuitbreaker:
instances:
backendA:
registerHealthIndicator: true
slidingWindowSize: 100
backendB:
registerHealthIndicator: true
slidingWindowSize: 10
permittedNumberOfCallsInHalfOpenState: 3
slidingWindowType: TIME_BASED
recordFailurePredicate: io.github.robwin.exception.RecordFailurePredicate
resilience4j.timelimiter:
instances:
backendA:
timeoutDuration: 2s
cancelRunningFuture: true
backendB:
timeoutDuration: 1s
cancelRunningFuture: false
-
ReactiveResilience4JCircuitBreakerFactory.create("backendA")
或Resilience4JCircuitBreakerFactory.create("backendA")
将应用instances backendA properties
-
ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")
或Resilience4JCircuitBreakerFactory.create("backendA", "groupA")
将应用instances backendA properties
-
ReactiveResilience4JCircuitBreakerFactory.create("backendC")
或Resilience4JCircuitBreakerFactory.create("backendC")
将应用global default properties
-
ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")
或Resilience4JCircuitBreakerFactory.create("backendC", "groupC")
将应用global default CircuitBreaker properties and config groupC TimeLimiter properties
要获取 Resilience4j 属性配置的更多信息,请参见 Resilience4J Spring Boot 2 Configuration。
Disabling the TimeLimiter
默认情况下,TimeLimiter
已启用,每个执行都由时间限制支持。此时间限制可显式定义,或使用默认时间限制(由 io.github.resilience4j.timelimiter.TimeLimiterConfig#ofDefaults
提供)。
可通过将属性 spring.cloud.circuitbreaker.resilience4j.disable-time-limiter
设置为 true
来全局禁用 TimeLimiter
。
spring:
cloud:
circuitbreaker:
resilience4j:
disable-time-limiter: true
此类选项仅在 spring-cloud-circuitbreaker
中的全局范围内提供,适用于基本和反应式断路器实现。