Adding the resilience mechanisms to the source code
Before we add the resilience mechanisms to the source code, we will add code that makes it possible to force an error to occur, as a delay and/or as a random fault. Next, we will add a circuit breaker together with a time limiter to handle slow or unresponsive APIs, as well as a retry mechanism that can handle faults that happen randomly. Adding these features from Resilience4j follows the Spring Boot way, which we have been using in the previous chapters:
- Add a starter dependency on Resilience4j in the build file
- Add annotations in the source code where the resilience mechanisms will be applied
- Add a configuration that controls the behavior of the resilience mechanisms
Handling resilience challenges is a responsibility of the integration layer; therefore, the resilience mechanisms will be placed in the ProductCompositeIntegration
class. The source code in the business logic, implemented in the ProductCompositeServiceImpl...