gpt4 book ai didi

java - 在后台运行 Spring-retry

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:49:20 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com