GithubHelp home page GithubHelp logo

bootcamptoprod / spring-boot-resilience4j-circuit-breaker Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 10 KB

A simple app demonstrating how we can implement circuit breaker pattern using Resilience4j in Spring Boot

Home Page: https://bootcamptoprod.com/spring-boot-resilience4j-circuit-breaker/

Java 100.00%
circuit-breaker circuit-breaker-pattern circuitbreaker circuitbreakerpattern java java-17 resilience resilience4j resilience4j-circuitbreaker resiliency

spring-boot-resilience4j-circuit-breaker's Introduction

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

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]

spring-boot-resilience4j-circuit-breaker's People

Contributors

bootcamptoprod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.