MicroProfile Fault Tolerance
So, we have our service configured and we can check its health. The next step for a microservice to become cloud-native is adding some resilience. The service should be able to self-heal within certain limits.
There are six annotations available within MicroProfile Fault Tolerance that can help make your service more robust:
@
Asynchronous
@
Retry
@
Timeout
@
Bulkhead
@
CircuitBreaker
@
Fallback
It is good to know that these annotations can be added to both CDI beans and public methods within those beans. Under the hood, they are implemented via interceptors.
@Asynchronous
@Asynchronous
adds, well, asynchronous behavior to the method it annotates. It wraps them into a method that returns CompletableStage
on which the other fault tolerance annotation can be applied.
@Asynchronous
allows your code to run concurrently. Let’s have a look at an example:
@Inject // is annoted with @Asynchronous private CustomerDetailsService...