运行 Spring-后台重试

Run Spring-retry in background

是否可以在后台 运行 spring-retry(@Retryable) ? 我有以下用 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) {
            }
        }
    }

控制器

   @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 {
       }

当它重试并且我发送另一个请求时,应用程序没有响应。重试完成后才会响应

很遗憾,目前不支持异步重试。有添加支持的功能请求,可以看到here.

此外,来自同一个 link,建议使用 ExecutorFuture 来实现异步重试。