07: Spring Cloud with Resilience4j CircuitBreaker

Q. What is Resilience4j?
A. Resilience4j is a fault-tolerance library implementing the Circuit Breaker pattern inspired by Netflix Hystrix, but offers a more convenient API and a number of other features like Rate Limiter to block too many frequent requests to some services, Bulkhead to limit the number of concurrent requests to a specific service, cacheing, fail retry, and time limiter.

Step 1: Go to https://start.spring.io/ to create a skeleton project for a REST web service with Resilience4j.

Spring with Resilience4j

Lombok is a java library that automatically plugs into your editor and build tools, and speed up your development by never have to write another getter or equals method again. Just with one annotation your class has a fully featured builder, automated logging variables, and much more.

Spring Reactive Web Spring Webflux with non-blocking IO server Netty for reactive web design, which is a set of techniques that can be used to build sites that always feel fast and responsive to user input regardless of the network speed or latency.

Click on “generate” to download the “circuit-breaker-se.zip” file.

Step 2: Unzip “circuit-breaker-se.zip” inside the “projects folder” and open this folder with your IDE of your choice. I am opening the with “Visual Studio Code” IDE.

Step 3: The pom.xml file.

Step 4: Create a new folder “service” under “com/example/circuitbreakerse” in “src/main/java“.


Simulates a failing condition by sending a “NullPointerException” when no “name” is passed.

Step 5: Create a new folder “controller” under “com/example/circuitbreakerse” in “src/main/java“.


REST Web service with CircuitBreaker.

Step 6: The main bootstrap class in “com/example/circuitbreakerse” under “src/main/java“.


Step 7: Build the jar and run it.


Step 8: Open a web browser.

URL: http://localhost:8080/hello?name=John
Output: Hello John!

CircuitBreaker in action when no “name” parameter is supplied.

URL: http://localhost:8080/hello
Output: Hello NoName

Java Interview FAQs

800+ Java Interview Q&As