java - 在后台运行 Spring-retry

标签 java spring spring-boot jpos

是否可以在后台运行 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) {
            }
        }
    }

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

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

最佳答案

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

另外,在同一个链接中,建议使用 ExecutorFuture 来实现异步重试。

关于java - 在后台运行 Spring-retry,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46463844/

相关文章:

java - 使用mockito powermokito 模拟重写方法

java - 如何设置spring dispatcherServlet路径?

java - 将实例转换为其真实类型

java - Java/Spring 中的全局状态

spring - 为什么 requiresSecure() 会导致 Spring Security 中的重定向循环?

spring - RESTEasy ExceptionMapper 不适用于 Spring Boot

java - Spring Boot 无法从资源文件夹加载 js 文件

Java嵌套类问题

GAE 上的 Spring Boot Rest App 抛出异常无法转换为 javax.persistence.EntityManagerFactory”

java - 如何在 Spring Boot 中使用 Apache Kafka 的数据