Circuit Breaker Properties Configuration

您可以在应用的配置属性文件中配置 CircuitBreakerTimeLimiter 配置或实例。属性配置的优先级高于 Java Customizer 配置。

You can configure CircuitBreaker and TimeLimiter configs or instances in your application’s configuration properties file. Property configuration has higher priority than Java Customizer configuration.

优先级从高到低依次下降。

Descending priority from top to bottom.

  • Method(id) config - on specific method or operation

  • Service(group) config - on specific application service or operations

  • 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") or Resilience4JCircuitBreakerFactory.create("backendA") will apply instances backendA properties

  • ReactiveResilience4JCircuitBreakerFactory.create("backendA", "groupA") or Resilience4JCircuitBreakerFactory.create("backendA", "groupA") will apply instances backendA properties

  • ReactiveResilience4JCircuitBreakerFactory.create("backendC") or Resilience4JCircuitBreakerFactory.create("backendC") will apply global default properties

  • ReactiveResilience4JCircuitBreakerFactory.create("backendC", "groupC") or Resilience4JCircuitBreakerFactory.create("backendC", "groupC") will apply global default CircuitBreaker properties and config groupC TimeLimiter properties

要获取 Resilience4j 属性配置的更多信息,请参见 Resilience4J Spring Boot 2 Configuration

For more information on Resilience4j property configuration, see Resilience4J Spring Boot 2 Configuration.

Disabling the TimeLimiter

默认情况下,TimeLimiter 已启用,每个执行都由时间限制支持。此时间限制可显式定义,或使用默认时间限制(由 io.github.resilience4j.timelimiter.TimeLimiterConfig#ofDefaults 提供)。

By default, the TimeLimiter is enabled and every execution is backed by a time limit. This time limit is either defined explicitly or the default time limit (provided by io.github.resilience4j.timelimiter.TimeLimiterConfig#ofDefaults) is used.

可通过将属性 spring.cloud.circuitbreaker.resilience4j.disable-time-limiter 设置为 true 来全局禁用 TimeLimiter

The TimeLimiter can be globally disabled by setting the property spring.cloud.circuitbreaker.resilience4j.disable-time-limiter to true.

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

此类选项仅在 spring-cloud-circuitbreaker 中的全局范围内提供,适用于基本和反应式断路器实现。

This type of option is only provided on a global scope within the spring-cloud-circuitbreaker and applies to the basic and to the reactive circuitbreaker implementation.