I am new to Resilience4J and trying to integrate with Spring boot.
My application has several remote system calls. I expect the same circuit breaker configuration for all remote calls.
I am using java configuration and functional style of decorating the remote calls with resilience4J operators. Currently, I defined one circuit breaker and one retry bean for all the remote system calls.
@Bean
public CircuitBreakerConfig circuitBreakerConfig() {
return CircuitBreakerConfig.custom().slidingWindowType(SlidingWindowType.COUNT_BASED).slidingWindowSize(6)
.failureRateThreshold(50).waitDurationInOpenState(Duration.ofSeconds(10))
.permittedNumberOfCallsInHalfOpenState(3).recordExceptions(HttpClientErrorException.class, HttpServerErrorException.class,TimeoutException.class,SdkClientException.class,AmazonServiceException.class,SQLException.class,JDBCException.class, DataAccessException.class).build();
}
@Bean
public CircuitBreaker circuitBreaker(CircuitBreakerConfig circuitBreakerConfig) {
return CircuitBreaker.of("circuit-config", circuitBreakerConfig);
}
@Bean
public RetryConfig retryConfig() {
return RetryConfig.custom().maxAttempts(3).waitDuration(Duration.ofMillis(1000))
.retryExceptions(HttpClientErrorException.class, HttpServerErrorException.class,TimeoutException.class,SdkClientException.class,AmazonServiceException.class,SQLException.class,JDBCException.class, DataAccessException.class).build();
}
@Bean
public Retry retry() {
return Retry.of("retry-config", retryConfig());
}
Decorators.ofRunnable(systemA::callA)
.withCircuitBreaker(circuitBreaker)
.withRetry(retry)
.decorate()
.run();
Decorators.ofRunnable(systemB::callB)
.withCircuitBreaker(circuitBreaker)
.withRetry(retry)
.decorate()
.run();
But I observed that in this way the circuit breaker (and its internal ring buffer) are shared between System A and System B.Due to this, failures of one remote system are effecting the failure threshold of another remote system.
I need to have a separate circuit breaker for each remote system so that the failure threshold is maintained per remote system. But the circuit Beaker configuration remains the same across remote systems.
What is the best practice to achieve this?