I have a Mutiny reactive stream on an Uni where I want to implement the following behavior:
This is what I got:
someUni
.onFailure().invoke(e -> log.info("Error {}", e.getMessage()))
.onFailure().retry().withBackOff(Duration.ofMillis(100), Duration.ofSeconds(5)).atMost(5)
.onFailure()
.invoke(() -> log.info("Retries exhausted, Im going to give up."))
.onFailure().recoverWithItem(Response.ok().build());
It does not look very neat, I had to call onFailure()
every time I needed to chain a new operator. That's because onFailure()
returns UniOnFailure<T>
, but once you chain something else you're back with the regular Uni<T>
. Is there a cleaner way to do this?
This is actually the correct way to do what you describe.
onFailure
is a group (not an operator) to define what to do upon failure, the Mutiny API was designed this way for readability purposes.