vert.xverticescircuit-breakervertx-eventbus

How to skip retry in vertx circuit breaker based on condition


I am currently using Vertx CircuitBreaker to attempt retry on requesting event bus. Based on the ReplyException.ReplyFailure I want to skip or avoid retries.

For example I don't want retry when the event bus responds with ReplyFailure.RECIPIENT_FAILURE, because this kind of error are not application error instead logic validation failure.

Below is my code,

    CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
                    new CircuitBreakerOptions()
                            .setMaxFailures(2) 
                            .setTimeout(5 * 1000) 
                            .setFallbackOnFailure(true) 
                            .setResetTimeout(5000) 
                            .setMaxRetries(2)
).retryPolicy(retryCount -> retryCount * 5000L);

Using circuit breaker as below,

breaker.execute(promise -> {  
            vertx.eventBus().<JsonObject>request(address, jsonObject, deliveryOptions)
                    .onComplete(event -> {

Based on the event I wan't circuit breaker to give up on retry. I tried checking event status and then called promise.complete method with the exception, though circuit breaker identifies that as failure and starts retrying. How can I tell circuit breaker to stop retrying?

I think the circuit breaker object could have

  1. A method to shutdown it
  2. A method to stop retry
  3. A method to increment failure

Update 1 ---------------------

I have implemented the retry part on my own and for timing out the operation I can set timer and check the status of the operation, if the operation is not completed I can start retry logic. But I don't have clues on how can I cancel the operation before retrying the next one, for example how can I cancel the event bus request?

Update 2 -----------------

Vertx circuit breaker too is not handling the timed out operations. I can see older response from event bus while retry is in progress. This might confuse application logic if not handled properly.


Solution

  • This is not currently supported by the Vert.x Circuit Breaker API. There is an open issue about it here. There's also a PR that attempts to fix it, but it has been sitting around for a year now. Not sure why it never got reviewed.