简体   繁体   中英

How to record each throwable when using .onFailure().retry() with delay between retries

I need to record failure reason in metrics for each failed http call when using Vert.x WebClient. This compiles:

               .onFailure()
                   .retry()
                   .withBackOff(Duration.ofMillis(INITIAL_RETRY_DELAY_MS))
                   .until(retryTimeExpired(wrapper))

I'm recording metrics in retryTimeExpired method. But at runtime I get this:

Caused by: java.lang.IllegalArgumentException: Invalid retry configuration, `when` cannot be used with a back-off configuration
    at io.smallrye.mutiny.groups.UniRetry.when(UniRetry.java:156)
    at io.smallrye.mutiny.groups.UniRetry.until(UniRetry.java:137)

I could of course add sleep but this is reactive. It would be possible to block for a short time but I would hate to block the thread. Any ideas how to do this without sleep ?

You could try using many sequential onFailure s. As long as the first doesn't handle the exception ( recoverWithItem , recoverWithNull , recoverWithUni ) or throw its own the next should observe the same failure.

service.apiMethod(key)
    .invoke(record -> logger.info("Succeeded to read record."))
    .onFailure()
        .invoke(exception -> logger.warn("Failed to read record."))
    .onFailure()
        .retry().withBackOff(delay).indefinitely();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM