繁体   English   中英

如何在重试之间延迟使用.onFailure().retry() 时记录每个 throwable

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

使用 Vert.x WebClient 时,我需要在指标中记录每个失败的 http 调用的失败原因。 这编译:

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

我在retryTimeExpired方法中记录指标。 但在运行时我得到这个:

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)

我当然可以增加sleep ,但这是被动的。 可以短时间阻塞,但我不想阻塞线程。 任何想法如何在不sleep的情况下做到这一点?

您可以尝试使用许多连续的onFailure s。 只要第一个不处理异常( recoverWithItemrecoverWithNullrecoverWithUni )或抛出自己的异常,下一个应该观察到同样的失败。

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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