5

Is it possible to run the spring-retry(@Retryable) in background ? I have below code which wrote in JPOS

public class RequestListener implements ISORequestListener, Configurable {
    private Logger logger = LoggerFactory.getLogger(RequestListener.class);
    private static ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;

    @Override
    public boolean process(ISOSource source, ISOMsg msg) {
        logger.info("iso request: {}", msg);
        scheduledThreadPoolExecutor.schedule(new Process(source, msg), 0, TimeUnit.SECONDS);
        return true;
    }

    @Override
    public void setConfiguration(Configuration configuration) throws ConfigurationException {
        scheduledThreadPoolExecutor = ConcurrentUtil.newScheduledThreadPoolExecutor();
    }

    @AllArgsConstructor
    class Process implements Runnable {
        private ISOSource source;
        private ISOMsg msg;

        @Override
        public void run() {
            switch (msg.getString(5)) {
                case "45":
                    try {
                        proc710000();
                    } catch (IOException e) {
                        e.printStackTrace();
                    } 
                    break;
            }
        }

        private void proc710000() throws IOException, ISOException {
            try {
                RestTemplate restTemplate = new RestTemplate();
                ResponseEntity<Dto> responseEntity = restTemplate.exchange(url + "/abc/" + Id, HttpMethod.POST, entity, Dto.class);  // call controller class
            } catch (HttpStatusCodeException ex) {
            }
        }
    }

Controller

   @Retryable(maxAttemptsExpression = "#{${max.read.attempts}}", backoff = @Backoff(delayExpression = "#{${retry.delay}}", multiplierExpression = "#{${multiplier}}", maxDelayExpression = "#{${max.delay}}"))
        @PostMapping("abc/{Id}")
        public void confirmation(@PathVariable("Id") String Id, @RequestBody JposDto jpos) throws ISOException, ParseException, IOException {
       }

While it retrying and I send another requset, the application is not responses. It will only responses after finished retrying.

1 Answers1

4

Unfortunately, asynchronous retry is not supported at the moment. There is a feature request to add the support, you can see it here.

Also, from the same link, there is a suggestion to use Executor with Future to implement asynchronous retries.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102