Implementing the fault tolerance mechanisms
Faults and failures are inevitable in a microservice environment. As the numbers of distributed components increase, the number of faults both within each component and those originating from their interactions increase as well. Any microservices application must have built-in resilience for these unfortunate scenarios. In this section, we will explore and implement different ways to handle faults and failures in the Micronaut framework.
Leveraging built-in mechanisms
Micronaut is a cloud-native framework and has built-in capabilities to handle faults and failures. Essentially, its fault tolerance is driven by retry advice. Retry advice offers the @Retryable
and @CircuitBreaker
annotations that can be used in any HTTP client.
Using @Retryable in an HTTP client
@Retryable is an effortless but effective fault tolerance mechanism – to put it simply, it's used to try again in case of a failure. These try attempts can be...