How to configure resilience4j.circuitbreaker in @Bean without properties.yml
See original GitHub issueThanks for raising a Resilience4j issue. Please provide a brief description of your problem along with the versions you are using. If possible, please also consider putting together a complete JUnit test that reproduces the issue.
Resilience4j version:
Java version: 8
Problem description:
Hi, I’m trying to configure resilience without the need to put the settings in the properties.yml. I created my configuration bean but the circuit is not working
@Slf4j
@Configuration
@Component
@RefreshScope
public class CircuitBreakerAutoConfiguration {
@Bean
public CircuitBreakerRegistry defaultGenesisCircuitBreaker(
@Value("${application.circuit-breaker.genesis.default."
+ "ringBufferSizeInClosedState:30}")
int ringBufferSizeInClosedState,
@Value("${application.circuit-breaker.genesis.default."
+ "ringBufferSizeInHalfOpenState:10}")
int ringBufferSizeInHalfOpenState,
@Value("${application.circuit-breaker.genesis.default."
+ "failureRateThreshold:50}")
long failureRateThreshold,
@Value("${application.circuit-breaker.genesis.default."
+ "waitDurationInOpenState:10000}")
long waitDurationInOpenState) {
log.info("Configuring custom Genesis Circuit Breaker genesis.default");
return CircuitBreakerRegistry.of(circuitBreakerConfig());
}
@Bean
public CircuitBreakerConfig circuitBreakerConfig() {
log.info("circuitBreakerConfig");
return CircuitBreakerConfig.custom()
.minimumNumberOfCalls(2)
.failureRateThreshold(50)
.waitDurationInOpenState(Duration.ofMillis(1000))
.permittedNumberOfCallsInHalfOpenState(2)
.slidingWindowSize(2)
.build();
}
@Bean
public CircuitBreaker defaultCircuitBreaker() {
CircuitBreakerConfig config = CircuitBreakerConfig.custom()
.minimumNumberOfCalls(2)
.build();
return CircuitBreaker.of("default", config);
}
}
I need to abstract this configuration to put it within a framework of my own. The only way it works is when I put the settings in the properties
resilience4j.circuitbreaker:
configs:
default:
registerHealthIndicator: false
slidingWindowSize: 10
minimumNumberOfCalls: 5
Issue Analytics
- State:
- Created 4 years ago
- Comments:21 (7 by maintainers)
Top Results From Across the Web
Configuring Resilience4J Circuit Breakers - Spring
You can configure CircuitBreaker and TimeLimiter instances in your application's configuration properties file. Property configuration has higher priority than ...
Read more >Bean Configuration for Circuit Breaker of Resilience4J Using ...
The above config would work. Try setting a minimumNumberOfCalls to lower value(10) default value is 100. The circuit breaker needs to encounter ...
Read more >Getting Started - resilience4j
You can configure your CircuitBreaker, Retry, RateLimiter, Bulkhead, Thread pool bulkhead and TimeLimiter instances in Spring Boot's application.yml config file ...
Read more >Resilience4j Tutorial with Spring Boot | Circuit Breaker, Retry ...
In this tutorial, we will implement Resilience4j with Spring boot and different modules available for it. We will see the theory part and ......
Read more >Circuit Breaker using Resilience4j | by Rupali Gupta - Medium
Add the required configurations to application.yml file or application.properties file resilience4j: circuitbreaker: configs: default:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Like @RobWin indicated, I Autowired the CircuitBreakerRegistry instead of creating my own through CircuitBreakerRegistry.of(config). This allowed me to use registry.circuitBreaker(name, config) to add new circuit breakers with my custom configurations in my code without any yaml entries.
How to use this for multiple circuit breaker instances?