resilience4j bulkhead skipping fallback method for certain type of exceptions

1k views Asked by At

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;
} 
2

There are 2 answers

0
Robert Winkler On BEST ANSWER

Just use a different fallbackMethod signature:

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

I think there is an issue with the latest Spring Boot and Spring Cloud version. I tested the old ones and the Bulkhead pattern worked for me.

Please, check my Maven POM.

Add the following Spring Boot version

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.3.RELEASE</version>
    <relativePath/>
</parent>

Add the following Spring Cloud and Resilience4j library version

<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Hoxton.SR1</spring-cloud.version>
    <resilience4j.version>1.5.0</resilience4j.version>
</properties>

   <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-spring-boot2</artifactId>
        <version>${resilience4j.version}</version>
    </dependency>

Add the following dependencies

    <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-circuitbreaker</artifactId>
        <version>${resilience4j.version}</version>
    </dependency>
    <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-timelimiter</artifactId>
        <version>${resilience4j.version}</version>
    </dependency>
    <dependency>
        <groupId>io.github.resilience4j</groupId>
        <artifactId>resilience4j-bulkhead</artifactId>
        <version>${resilience4j.version}</version>
    </dependency>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>