This repo contains a collection of apps that demonstrate how to using Spring Cloud CircuitBreaker with various circuit breaker implementations.
The non-reactive example can be found in spring-cloud-circuitbreaker-resilience4j
.
When these apps are running there are two endpoints available for testing
-
/get
- This endpoint makes a request to httpbin's/get
endpoint and returns the data -
/delay/{seconds}
- This endpoint makes a request to httpbin's/delay
endpoint passing the delay in the response in seconds. Since this request can take a significant amount of time it is wrapped in a circuit breaker. If theseconds
parameter is greater than or equal to 3 the circuit breaker will time out and return the response{"hello": "world"}
.
There are two reactive samples in this repo, spring-cloud-circuitbreaker-demo-reactive
and spring-cloud-circuibreaker-demo-reactive-resilience4j
.
Both of these samples contain the same two endpoints as the non-reactive samples
(which in this case return a Mono
), but also
contain an additional endpoint to demonstrate the use of Flux
. This endpoint can be
accessed by calling /fluxdelay/{seconds}
. It has the same functionality as /delay/{seconds}
but the fallback returns a Flux
.
This sample demonstrates how to using Spring Cloud CircuitBreaker with reactive types from RxJava2 and CompletableFuture. There are four endpoints available for testing in this app
/rxjava2/get
/rxjava2/delay/{seconds}
/completablefuture/get
/completablefuture/delay/{seconds}
Each of these have the same functionality as the other endpoints in the other apps.
With Spring Cloud CircuitBreaker and Resilience4J you can easily collect metrics about
the circuit breakers in your app. This is demoed in both spring-cloud-circuitbreaker-demo-resilience4j
and spring-cloud-circuitbreaker-demo-reactive-resilience4j
. You can see the metrics available
by hitting /actuator/metrics
.
NOTE: The code wrapped by the circuit breaker needs to be executed before any metrics appear
You can also have these metrics collected by Prometheus and visualized in Grafana. To demonstrate
this, the repo contains a Docker Compose file that will start Prometheus and Grafana locally
and scrape the metrics being surfaces at /actuator/prometheus
. To see it in action
- Start either
spring-cloud-circuitbreaker-demo-resilience4j
orspring-cloud-circuitbreaker-demo-reactive-resilience4j
. cd
into thegrafana
directory in the root of the repo- Run
docker-compose up
- Go to http://localhost:3000 and login with the username
admin
and the passwordadmin
- There will be a datasource pointing to the docker container running Prometheus and dashboard already configured to visualize the Resilience4J metrics
- Make some requests to the
/delay
endpoint. You can easily do this with a tool likewatch
. For examplewatch -n 1 http :8080/delay/5
. - If you refresh the Grafana dashboard or set its automatic refresh you should see the graphs begin to change as requests are made.