Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resilience4j Not Ignoring Exceptions

JobServiceImpl.java:

@CircuitBreaker(name = "jobsApiServiceGetAllJobs", fallbackMethod = "getAllJobsFallback")
public ResponseEntity<JobsResponse> getAllJobs() {
    ...
    throw new ApiException();
}

public ResponseEntity<JobsResponse> getAllJobsFallback(Throwable throwable) {
    log.error("Fallback method called");
}

application.properties:

resilience4j.circuitbreaker.instances.jobsApiServiceGetAllJobs.ignoreExceptions=ccp.shared.platform.exception.ApiException,ccp.shared.platform.exception.BadRequestApiException

Whenever ccp.shared.platform.exception.ApiException is thrown, the fallback method is called even though I have added it in the ignoreExceptions list in the application.properties file. I want it to not trigger the fallback method when ApiException is thrown. I have tried similar questions on stack overflow and those does not work for me. Am I doing anything wrong?

like image 653
Arshad Yusuf Avatar asked Sep 16 '25 04:09

Arshad Yusuf


1 Answers

Seems that the property is defined in the docs but actually, it does not work. There is a pull request for that -> CircuitBreakerConfigurationProperties has no ignoreException property.

You can use the common Spring+java configuration to achieve that in the meantime:

@Bean
CircuitBreaker reportingApiCircuitBreaker(CircuitBreakerRegistry registry) {
    CircuitBreakerConfig config = CircuitBreakerConfig.custom()
        .ignoreExceptions(ApiException.class, BadRequestApiException.class)
        .build();

    return registry.circuitBreaker("yourCircuitBreakername", config);
}
like image 131
Felipe Avatar answered Sep 17 '25 18:09

Felipe