I had the same situation and I found a solution to solve the problem. Give an answer in the hope that this will help someone else. You can set the maximum number of attempts and the time interval for each attempt.
@Bean public RetryTemplate retryTemplate() { int maxAttempt = Integer.parseInt(env.getProperty("maxAttempt")); int retryTimeInterval = Integer.parseInt(env.getProperty("retryTimeInterval")); SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(); retryPolicy.setMaxAttempts(maxAttempt); FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy(); backOffPolicy.setBackOffPeriod(retryTimeInterval);
And my rest service, which I want to perform, is below.
retryTemplate.execute(context -> { System.out.println("inside retry method"); ResponseEntity<?> requestData = RestTemplateProvider.getInstance().postAsNewRequest(bundle, ServiceResponse.class, serivceURL, CommonUtils.getHeader("APP_Name")); _LOGGER.info("Response ..."+ requestData); throw new IllegalStateException("Something went wrong"); });
source share