Read this first post to understand the concept.
On December of 2018, Spring announced that Spring Cloud Netflix projects entering maintenance mode and following that announcement recommended some replacements, including Resilience4j instead of Hystrix.
Resilience4j is a lightweight fault tolerance library designed for Java 8 and functional programming. The library uses Vavr, which does not have any other external library dependencies. Resilience4j allows picking what you need.
The Resilience4j repository also provides several implementation patterns that can make your application more robust, including a circuit breaker, time limiter, rate limiter, retry and cache.
The combination of Prometheus and Grafana is becoming a more and more common monitoring stack used by DevOps teams for storing and visualizing time series data. Prometheus acts as the storage backend and Grafana as the interface for analysis and visualization.
The demo project uses this combination along with the Prometheus Metrics exporter module from Resilience4j to turn easy the analysis and visualization of the metrics generated by Resilience4j. And the most important, if you already have docker on the machine, it takes less than 1 minute to configure this demo.
The full demo code is below.
The setup to start grafana and prometheus application (via docker) and the both configurations are available in the project readme in github.
Circuit breaker settings are in the application.yml file.
- This are the protected methods by circuit breaker
Use the project endpoints to simulate successes.
And for simulate failures.
- To simulate the status OPEN, call failure endpoint until it let is reach threshold of 5 attempts used in settings.
When the status is OPEN, the remote call (BackendAConnector.class#failure) will not be executed and all further calls to the circuit breaker will return the error "CircuitBreaker 'backendA' is OPEN...".
We can see the status and metrics generated through the grafana dashboards:
A Spring Boot 2 demo which shows how to use the Resilience4j Spring Boot 2 Starter
Spring Boot 2 demo of Resilience4j
This demo shows how to use the fault tolerance library Resilience4j in a Spring Boot 2 application.
See User Guide for more details.
Just run the application in your IDE.
Application is running on http://localhost:9080.
Monitoring with Prometheus and Grafana (OPTIONAL)
Use docker-compose to start grafana and prometheus servers.
- In the root folder
docker-compose -f docker-compose.yml up
Check the prometheus server.
- Open http://localhost:9090
- Access status -> Targets, both endpoints must be "UP"
Configure the grafana.
- Open http://localhost:3000
Configure integration with Prometheus
- Access configuration
- Add data source
- Select prometheus
- Use url "http://localhost:9080" and access with value "Browser"
- Access "home"
- Import dashboard
- Upload dashboard.json from /docker
Copyright 2019 Robert Winkler
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except…
The Full demo project with all modules can viewed here.
In this post, we can see how its works and how is possible to monitoring the Circuit Breaker implemented in Spring Boot 2 with Resilience4j, Prometheus and Grafana.