vertx-circuit-breaker
vertx-circuit-breaker copied to clipboard
Support Cancelling Retries
Describe the feature
Presently, the retryPolicy
method specifies how often the circuit breaker should try before failing; however, in certain cases (e.g. expected failures) it is not desirable to continue retrying.
(If this feature exists, I couldn't find any mention of this in the documentation.)
Use cases
Something like a retryOrCancelPolicy
would be desirable, where returning -1L
would cease the circuit breaker from retrying:
CircuitBreaker.create("my-circuit-breaker", vertx)
.retryOrCancelPolicy { retryCount: Int, cause: Throwable? ->
if (cause is MyExpectedException) {
-1L
} else {
retryCount * 1000L
}
}
I tend to use michaelbull/kotlin-retry for retrying, which has a pretty elegant way of handling retry policies.
For example:
val retryTimeouts: RetryPolicy<Throwable> = {
if (reason is SQLDataException) ContinueRetrying else StopRetrying
}
suspend fun printExchangeBetween(a: Long, b: Long) {
val customer1 = customers.nameFromId(a)
val customer2 = customers.nameFromId(b)
println("$customer1 exchanged with $customer2")
}
fun main() = runBlocking {
retry(retryTimeouts + limitAttempts(5) + constantDelay(20)) {
printExchangeBetween(1L, 2L)
}
}
Contribution
I will try to realize this if I get the time; right now I'm holed up with my work laptop, which does not allow me to push externally... even posting this issue was a pain. :|
@rgmz that would be a great contribution