I have used spring @Retryable
to implement retry function call if there is any problems occurs when calling another service using RestTemplate
.
The function is given below, the problem is that I have given maxAttempts to 4 in case of any exception happens it should try for 4 times. But even without any exception the function is executing 4 times and four entries of employee is created in the DB.
createEmployee function which calls another service for creating the employee in DB
@Retryable(value = { Exception.class }, maxAttempts = 4, backoff = @Backoff(delay = 1000))
public Response createEmployee(EmployeeRequest employeeRequest)
{
log.info(“creating employee”)
:
// calls another micro service using RestTemplate which creates employee into the DB
:
}
@EnableRetry
in AppConfig
@Configuration
@EnableRetry
public class AppConfig {
}
Can anyone please help me on this