How to Use Multiple Strategies
It is possible to use multiple fault tolerance strategies to guard a single method. For example, it is possible to use fallback together with retry and timeout:
@ApplicationScoped
public class MyService {
@Retry(maxRetries = 5)
@Fallback(fallbackMethod = "fallback")
@Timeout
public String hello() {
...
}
public String fallback() {
return "fallback";
}
}
In such case, the fault tolerance strategies are nested in a pre-defined order:
Fallback(
Retry(
CircuitBreaker(
RateLimit(
Timeout(
Bulkhead(
... the guarded method ...
)
)
)
)
)
)
In the previous example, this means that timeout is nested inside retry, which in turn is nested inside fallback. If the method times out (the default timeout is 1 second), it is retried (up to 5 times). If no attempt succeeds, fallback is used.