4

是否可以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 {
       }

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

4

1 回答 1

3

不幸的是,目前不支持异步重试。有一个添加支持的功能请求,您可以在此处查看

此外,从同一个链接,有一个建议使用ExecutorwithFuture来实现异步重试。

于 2017-09-28T08:01:23.850 回答