是否可以在后台运行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 {
}
当它重试并发送另一个requset时,应用程序不是响应。它只会在完成重试后才会响应。