Circuit Breaker
Circuit Breaker with Resilience4J
10-15 min
Circuit Breaker with Resilience4J
The Circuit Breaker pattern is essential for managing resilience in microservices architectures. Resilience4J is a lightweight, functional library that implements this pattern, along with other resilience patterns.
1. Basic Configuration
1.1 Adding Dependencies
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot3</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
1.2 Configuring the Circuit Breaker
# application.yml
resilience4j:
circuitbreaker:
instances:
productService:
slidingWindowSize: 10
failureRateThreshold: 50
waitDurationInOpenState: 5000
permittedNumberOfCallsInHalfOpenState: 3
eventConsumerBufferSize: 10
ratelimiter:
instances:
productService:
limitForPeriod: 100
limitRefreshPeriod: 1s
timeoutDuration: 0
retry:
instances:
productService:
maxAttempts: 3
waitDuration: 100
enableExponentialBackoff: true
exponentialBackoffMultiplier: 2
exponentialBackoffMaxDuration: 600
retryExceptions:
- org.springframework.web.client.RestClientException
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion