Resilience4j Retry with resultPredicate not working

109 views Asked by At

I am trying to use the retry for the first time. It should only try to contact 3 more times with status code 500. Unfortunately this does not work. Where is the error?

Dependencies:

implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: '3.1.6'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-circuitbreaker-resilience4j', version: '3.0.3'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '3.1.6'

Definition:

@Component
public class MyService{
     @Retry(name ="throwingFeignException")
     public String sendUser(Request request) {
      Response response = feignClient.send(eaziRequest);
      return response.getId();
    }
}

and the difinition in application.yaml:

resilience4j:
  retry:
    instances:
      throwingFeignException:
        maxAttempts: 3
        waitDuration: 60s
        retryExceptions:
          - feign.FeignException
        ignoreExceptions:
          - java.lang.Exception
        enableExponentialBackoff: true
        exponentialBackoffMultiplier: 5
        resultPredicate: de.ruv.stammdaten.domain.eazi.backend.exception.ServerInternalErrorVerifier

and my predicate looks like this:

@Slf4j
    public class ServerInternalErrorVerifier implements Predicate<FeignException> {
    
        @Override
        public boolean test(FeignException exception) {
    
            if(isServerError(exception)){
                log.error("Server '{}' could not be achieved due of '{}'", exception.request().url(), exception.getMessage());
                return true;
            }
            return false;
        }
    
        private static boolean isServerError(FeignException exception) {
            return exception.status() >= HttpStatus.INTERNAL_SERVER_ERROR.value();
        }
    }

sendUser method wont be excuted again and my predicate also not working, what is wrong here?

1

There are 1 answers

0
Roma Kap On

that was my mistake, i've expected reaction of retry to early, so i thought, it is not working