Understanding Eclipse MicroProfile Fault Tolerance
Fault Tolerance provides a collection of tools that prevent code from failing by making it more resilient. Most of these tools are inspired by development good practices (such as retry or fallback) or well-known development patterns (such as circuit breaker or bulkhead).
Fault Tolerance is based on CDI and, more precisely, on the CDI interceptor implementation. It also relies on the MicroProfile Config specification to allow external configuration for Fault Tolerance policies.
The main idea of the specification is to decouple business logic from Fault Tolerance boilerplate code. To achieve that, the specification defines interceptor-binding annotations to apply Fault Tolerance policies on a method execution or on a class (in that case, all class methods have the same policy).
Policies included in the Fault Tolerance specification are the following:
- Timeout: This is applied with the @Timeout annotation. It adds a timeout to the current operation.
- Retry: This is applied with the @Retry annotation. It adds retry behavior and allows its configuration on the current operation.
- Fallback: This is applied with the @Fallback annotation. It defines the code to execute, should the current operation fail.
- Bulkhead: This is applied with the @Bulkhead annotation. It isolates failures in the current operation to preserve the execution of other operations.
- Circuit Breaker: This is applied with the @CircuitBreaker annotation. It provides an automatic fast failing execution to prevent overloading the system.
- Asynchronous: This is applied with the @Asynchronous annotation. It makes the current operation asynchronous (that is, code will be invoked asynchronously).
Applying one or more of these policies is as easy as adding the required annotations on the method (or the class) for which you'd like to have these policies enabled. So, using Fault Tolerance is rather simple. But this simplicity doesn't prevent flexibility, thanks to all of the configuration parameters available for each policy.
Right now, the following vendors provide an implementation for the Fault Tolerance specification:
- Red Hat in Thorntail and Quarkus
- IBM in Open Liberty
- Payara in Payara Server
- Apache Safeguard for Hammock and TomEE
- KumuluzEE for KumuluzEE framework
All of these implementations support Fault Tolerance and hence support the same set of features that are described in the next section.