简体   繁体   中英

Resilience4J in Springboot is not working as expecting

I'm trying to add resilience4j into my app for exponential backoff, etc.

Service

@Component
public class ResilienceService {
    private static final String BACKEND_A = "backendA";

    public ResilienceService() throws IOException {
        testRetry();
    }

    @Retry(name = BACKEND_A)
    public void testRetry() throws IOException {
        System.out.println("Hey it's working!");
        throw new IOException();
    }

}

Config

resilience4j.retry.instances.backendA.maxAttempts=3
resilience4j.retry.instances.backendA.waitDuration=10s
resilience4j.retry.instances.backendA.enableExponentialBackoff=true
resilience4j.retry.instances.backendA.exponentialBackoffMultiplier=2
resilience4j.retry.instances.backendA.retryExceptions[0]=java.io.IOException

I'm trying to basically see if resilience lib will call this function 3 times. How should I think about both configuring this correctly and also testing that the retries are actually happening? I thought I could put a breakpoint on the method and see it call 3 times, but maybe I'm misunderstanding.

Aside from the comment by @M.Deinum above, you may also have caught out by resilience4j-springboot2 not depending on spring aop by default.

Eg you might need:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
</dependencies>

To be fair, the documentation does state :

Add the Spring Boot 2 Starter of Resilience4j to your compile dependency.

The module expects that org.springframework.boot:spring-boot-starter-actuator and org.springframework.boot:spring-boot-starter-aopare already provided at runtime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM