此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 spring-cloud-CircuitBreaker 3.1.3! |
断路器属性配置
您可以在应用程序的配置属性文件中配置 and configs 或 instances。
Property configuration 的优先级高于 Java configuration。CircuitBreaker
TimeLimiter
Customizer
优先级从上到下降序。
-
Method(id) config - 针对特定方法或操作
-
Service(group) config - 针对特定应用程序服务或操作
-
全局默认配置
ReactiveResilience4JCircuitBreakerFactory.create(String id, String groupName)
Resilience4JCircuitBreakerFactory.create(String id, String groupName)
全局默认属性配置
resilience4j.circuitbreaker:
configs:
default:
registerHealthIndicator: true
slidingWindowSize: 50
resilience4j.timelimiter:
configs:
default:
timeoutDuration: 5s
cancelRunningFuture: true
Configs 属性配置
resilience4j.circuitbreaker:
configs:
groupA:
registerHealthIndicator: true
slidingWindowSize: 200
resilience4j.timelimiter:
configs:
groupC:
timeoutDuration: 3s
cancelRunningFuture: true
实例属性配置
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 配置。
禁用 TimeLimiter
默认情况下,启用,并且每次执行都有时间限制。此时间限制要么是显式定义的,要么是使用默认时间限制(由 提供)。TimeLimiter
io.github.resilience4j.timelimiter.TimeLimiterConfig#ofDefaults
可以通过将属性设置为 来全局禁用 。TimeLimiter
spring.cloud.circuitbreaker.resilience4j.disable-time-limiter
true
spring:
cloud:
circuitbreaker:
resilience4j:
disable-time-limiter: true
TimeLimiter
也可以使用以下方法为特定组或实例禁用:spring.cloud.circuitbreaker.resilience4j.disable-time-limiter-map
spring:
cloud:
circuitbreaker:
resilience4j:
disable-time-limiter-map:
group1: true
instanceA: false
instanceB: true
这些禁用选项在 basic 和 reactive 断路器实现中提供,并适用于这些实现。TimeLimit
spring-cloud-circuitbreaker
禁用的优先顺序为 : > > 。基于上述配置,已禁用但已启用。对于所有其他实例和组,它将回退到全局设置的值 如果未设置,则默认情况下,为其余断路器实例和组启用。instance
group
global
instanceB
group1
TimeLimiter
instanceA
spring.cloud.circuitbreaker.resilience4j.disable-time-limiter
spring.cloud.circuitbreaker.resilience4j.disable-time-limiter
TimeLimit