spring-cloud / spring-cloud-circuitbreaker

Spring Cloud Circuit Breaker API and Implementations
Apache License 2.0
335 stars 110 forks source link

TimeLimiterConfig in resilience4J circuit breaker #71

Closed eatgrass closed 3 years ago

eatgrass commented 4 years ago

just wondering why Resilience4JCircuitBreakerConfiguration takes 'TimeLimiterConfig' to determine timeout, why not using slowCallRateThreshold in CircuitBreakerConfig?

ryanjbaxter commented 3 years ago

I could be wrong but I think the two are slightly different.

A operation can be considered slow by setting slowCallDurationThreshold and the operation is still given the opportunity to complete. Once the slowCallRateThreshold is surpassed the circuit breaker will be tripped and calls will no longer be made.

The TimeLimiter stops the operation and returns once the TimeLimiter is surpassed.

eatgrass commented 3 years ago

@ryanjbaxter thanks for the explanation and I think there should be a way to customize the CircuitBreaker through slowCallDurationThreshold.

ryanjbaxter commented 3 years ago

You can customize that using Resilience4JConfigBuilder.circuitBreakerConfig

@Bean
public Customizer<Resilience4JCircuitBreakerFactory> defaultCustomizer() {
    return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
            .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofSeconds(4)).build())
            .circuitBreakerConfig(CircuitBreakerConfig.ofDefaults())
            .build());
}