https://github.com/bootcamptoprod/spring-boot-resilience4j-circuit-breaker
A simple app demonstrating how we can implement circuit breaker pattern using Resilience4j in Spring Boot
https://github.com/bootcamptoprod/spring-boot-resilience4j-circuit-breaker
circuit-breaker circuit-breaker-pattern circuitbreaker circuitbreakerpattern java java-17 resilience resilience4j resilience4j-circuit-breaker resilience4j-circuitbreaker resiliency resiliency-patterns resilient rest rest-api spring-boot spring-boot-3 spring-boot3
Last synced: 3 months ago
JSON representation
A simple app demonstrating how we can implement circuit breaker pattern using Resilience4j in Spring Boot
- Host: GitHub
- URL: https://github.com/bootcamptoprod/spring-boot-resilience4j-circuit-breaker
- Owner: BootcampToProd
- Created: 2024-03-16T12:38:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-17T14:46:58.000Z (about 1 year ago)
- Last Synced: 2025-01-07T14:46:18.496Z (5 months ago)
- Topics: circuit-breaker, circuit-breaker-pattern, circuitbreaker, circuitbreakerpattern, java, java-17, resilience, resilience4j, resilience4j-circuit-breaker, resilience4j-circuitbreaker, resiliency, resiliency-patterns, resilient, rest, rest-api, spring-boot, spring-boot-3, spring-boot3
- Language: Java
- Homepage: https://bootcamptoprod.com/spring-boot-resilience4j-circuit-breaker/
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Resilience4j Circuit Breaker: Ensuring System Stability
For complete understanding of Resilience4j Circuit Breaker and how we can integrate it inside the Spring Boot application you can checkout our blog.
**Blog Link:** [Resilience4j Circuit Breaker: Ensuring System Stability](https://bootcamptoprod.com/spring-boot-resilience4j-circuit-breaker/)# spring-boot-resilience4j-circuit-breaker
A simple app demonstrating how we can implement circuit breaker pattern using Resilience4j in Spring Boot## App Overview
This is a simple app wherein we are fetching the movie details based on the movie id. The movie details are fetched from external service that is called using the Spring Rest Template. For simplicity, we have created a mock controller which acts as a external service for returning the movie details.## Circuit Breaker Scenarios
We have created a single controller endpoint which accepts movie id as path parameter and query parameter circuitBreakerType which accepts predefined set of values to mimic the different circuit breaker examples.### Acceptable Values
#### For Path Parameter - Movie Id
a. **1** - Mock controller returns valid movie information
b. **2** - Mock controller returns valid movie information but with a delay
c. **3** - Mock controller returns HTTP status code 404
d. **4** or **any other numeric value** - Mock controller returns null which leads to MovieNotFound Exception#### For Query Parameter - circuitBreakerType
Different circuit breaker instances are defined inside the application.yml. To mimic different circuit breaker scenarios use:
a. **count-based-circuit-breaker:** countBasedCircuitBreaker circuit breaker instance will be triggered
b. **time-based-circuit-breaker:** timeBasedCircuitBreaker circuit breaker instance will be triggered.
c. **circuit-breaker-on-exception:** circuitBreakerOnException circuit breaker instance will be triggered.
d. **circuit-breaker-with-record-failure-predicate:** circuitBreakerWithRecordFailurePredicate circuit breaker instance will be triggered.
e. **circuit-breaker-with-ignore-exception-predicate:** circuitBreakerWithIgnoreExceptionPredicate circuit breaker instance will be triggered.
f. **circuit-breaker-for-slow-calls:** circuitBreakerForSlowCalls circuit breaker instance will be triggered.
g. **circuit-breaker-with-fallback:** countBasedCircuitBreaker circuit breaker instance will be triggered and fallback method logic will be executed in this case.
h. **custom-circuit-breaker:** customCircuitBreaker circuit breaker instance defined in CircuitBreakerConfiguration class will be triggered.## cURL Commands
Check the application logs in order to get the better understanding of different circuit breaker scenarios.### 1. Count Based Circuit Breaker
```
curl 'http://localhost:8080/movies/3?circuitBreakerType=count-based-circuit-breaker'
```### 2. Time Based Circuit Breaker
```
curl 'http://localhost:8080/movies/3?circuitBreakerType=time-based-circuit-breaker'
```### 3. Circuit Breaker on Exception
```
curl 'http://localhost:8080/movies/3?circuitBreakerType=circuit-breaker-on-exception'
```### 4. Circuit Breaker with Record Failure Predicate
```
curl 'http://localhost:8080/movies/4?circuitBreakerType=circuit-breaker-with-record-failure-predicate'
```### 5. Circuit Breaker with Ignore Exception Predicate
```
curl 'http://localhost:8080/movies/4?circuitBreakerType=circuit-breaker-with-ignore-exception-predicate'
```### 6. Circuit Breaker for Slow Calls
```
curl 'http://localhost:8080/movies/2?circuitBreakerType=circuit-breaker-for-slow-calls'
```### 7. Circuit Breaker with Fallback
```
curl 'http://localhost:8080/movies/3?circuitBreakerType=circuit-breaker-with-fallback'
```### 8. Custom Circuit Breaker
```
curl 'http://localhost:8080/movies/3?circuitBreakerType=custom-circuit-breaker'
```## Postman Collection
Additionally, the Postman collection is available under the resources folder.
[src > main > resources > postman > Spring-Boot-Resilience4j-Circuit-Breaker.postman_collection.json]