此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 spring-cloud-CircuitBreaker 3.1.3spring-doc.cn

断路器属性配置

您可以在应用程序的配置属性文件中配置 and configs 或 instances。 Property configuration 的优先级高于 Java configuration。CircuitBreakerTimeLimiterCustomizerspring-doc.cn

优先级从上到下降序。spring-doc.cn

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 propertiesspring-doc.cn

  • ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA")或将适用Resilience4JCircuitBreakerFactory.create("backendA", "groupA")instances backendA propertiesspring-doc.cn

  • ReactiveResilience4JCircuitBreakerFactory.create("backendC")或将适用Resilience4JCircuitBreakerFactory.create("backendC")global default propertiesspring-doc.cn

  • ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC")或将适用Resilience4JCircuitBreakerFactory.create("backendC", "groupC")global default CircuitBreaker properties and config groupC TimeLimiter propertiesspring-doc.cn

有关 Resilience4j 属性配置的更多信息,请参阅 Resilience4J Spring Boot 2 配置spring-doc.cn

禁用 TimeLimiter

默认情况下,启用,并且每次执行都有时间限制。此时间限制要么是显式定义的,要么是使用默认时间限制(由 提供)。TimeLimiterio.github.resilience4j.timelimiter.TimeLimiterConfig#ofDefaultsspring-doc.cn

可以通过将属性设置为 来全局禁用 。TimeLimiterspring.cloud.circuitbreaker.resilience4j.disable-time-limitertruespring-doc.cn

spring:
	cloud:
		circuitbreaker:
			resilience4j:
				disable-time-limiter: true

TimeLimiter也可以使用以下方法为特定组或实例禁用:spring.cloud.circuitbreaker.resilience4j.disable-time-limiter-mapspring-doc.cn

spring:
	cloud:
		circuitbreaker:
			resilience4j:
				disable-time-limiter-map:
					group1: true
					instanceA: false
					instanceB: true

这些禁用选项在 basic 和 reactive 断路器实现中提供,并适用于这些实现。TimeLimitspring-cloud-circuitbreakerspring-doc.cn

禁用的优先顺序为 : > > 。基于上述配置,已禁用但已启用。对于所有其他实例和组,它将回退到全局设置的值 如果未设置,则默认情况下,为其余断路器实例和组启用。instancegroupglobalinstanceBgroup1TimeLimiterinstanceAspring.cloud.circuitbreaker.resilience4j.disable-time-limiterspring.cloud.circuitbreaker.resilience4j.disable-time-limiterTimeLimitspring-doc.cn