[英]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。 只要第一個不處理異常( recoverWithItem
、 recoverWithNull
、 recoverWithUni
)或拋出自己的異常,下一個應該觀察到同樣的失敗。
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.