The fallback event handler
The fallback pattern enables your service to continue the execution in case of a failed request to another service. Instead of aborting the computation because of a missing response, you fill in a fallback value.
Typically, Fallbacks are called when Exceptions are thrown. Exceptions can
occur when the HTTP request fails, or when one of the FeignDecorators
activates the CircuitBreaker.
| Parameters | Description |
|---|---|
type |
always fallback |
exceptionTypes |
A collection of Exception classes that the fallback uses |
exceptionHandlerClass |
A class that handles the exception and returns an appropriate object, external |
exceptionHandler |
An object class that implements a Function that accepts a
Throwable and returns an appropriate response at runtime |
The following example shows the configuration code for sampleRESTApi
endpoint connection:
Config.builder()
.basePath(sampleRESTApiRule.baseUrl())
.eventHandler(FallbackSetup.builder()
.exceptionType(RetryableException.class)
.exceptionHandler(t -> Collections.singletonList(SAMPLE_API))
.build())
.build()
.buildAPI(sampleRESTApi.class)
.findAll()
See also:
