I am working on a springboot application and want to add the resilience4j- retry mechanism. I did the following steps:
Added the actuator, aop and resilience4j dependencies in pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot2</artifactId>
</dependency>
Created a method in the controller which will try and hit a dummy service(expected to fail). Added the @Retry annotation on my method.
@GetMapping("/sample-api")
@Retry(name = "sample-api")
private String sampleApi() {
log.info("Sample Api call receieved");
ResponseEntity<String> forEntity = new RestTemplate().getForEntity("http://localhost:8080/some-dummy-url", String.class);
return forEntity.getBody();
}
Added the configuration to the application.properties
resilience4j.retry.instances.sample-api.maxAttempts=5
Also, I tried with maxRetryAttempts. But nothing changes.
I expected it to retry number of times that has been configured in the application.properties. However, it just tries once. Not sure if I am missing something. Can somebody please help with this?
Annotated methods must be public and not private.