javaresilience4j

resilience4j bulkhead skipping fallback method for certain type of exceptions


I use reslience4j bulkhead to limit number of active threads to one of my service method. When the thread limit exceeds the configuration it should go to a fallback method which is happening as expected.

But as part of business logic in my method when the validation fails I throw BadRequestException with a custom message to my consumer. Here the control goes to a fallback method when the checkedException occurs too Ideally it should not be the case.

So do we have any configuration to skip the control goes to fallback method on certain type of Exceptions similar to how do we have in Hystrix?

@Bulkhead(name="bhName" fallbackMethod="fallbackMethod")
public void doSomething(){

    //validatiion
    // if validation succeeds
         //do some business logic
    // else if validation fails
        throw BadRequestException("Error Message")
}

public void fallbackMethod(Exception ex){
   log.info("The number of concurrency limit exceeded");
   return null;
} 

Solution

  • Just use a different fallbackMethod signature:

    public void fallbackMethod(BulkheadFullException ex){
       log.info("The number of concurrency limit exceeded");
       return null;
    }