事务执行消息推送

This commit is contained in:
2025-09-30 15:27:13 +08:00
parent 0e53da8d18
commit 22042eb66e
2 changed files with 63 additions and 32 deletions

View File

@@ -66,33 +66,46 @@ public class PrintMqListener {
@RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_MACHINE_PRINT_QUEUE})
public void orderPrint(String req) {
// 使用异步线程池执行延迟任务,不阻塞当前消费者线程
CompletableFuture.runAsync(() -> {
try {
// 延迟3秒处理
TimeUnit.SECONDS.sleep(3);
// 执行核心打印逻辑
invokeFun("orderPrint", "java.order", req, (data) -> {
JSONObject jsonObject = JSONObject.parseObject(data);
String orderId = jsonObject.getString("orderId");
if (orderId == null) {
throw new RuntimeException("订单打印失败未传递orderId");
}
Boolean printOrder = jsonObject.getBoolean("printOrder");
funUtil.runFunAndCheckKey(() -> {
printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
return null;
}, RedisCst.getLockKey("orderPrint", orderId));
});
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// 记录中断日志
log.warn("打印任务被中断req:{}", req, e);
} catch (Exception e) {
// 记录业务异常日志
log.error("打印任务处理失败req:{}", req, e);
// 执行核心打印逻辑
invokeFun("orderPrint", "java.order", req, (data) -> {
JSONObject jsonObject = JSONObject.parseObject(data);
String orderId = jsonObject.getString("orderId");
if (orderId == null) {
throw new RuntimeException("订单打印失败未传递orderId");
}
}, asyncExecutor);
Boolean printOrder = jsonObject.getBoolean("printOrder");
funUtil.runFunAndCheckKey(() -> {
printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
return null;
}, RedisCst.getLockKey("orderPrint", orderId));
});
// // 使用异步线程池执行延迟任务,不阻塞当前消费者线程
// CompletableFuture.runAsync(() -> {
// try {
// // 延迟3秒处理
// TimeUnit.SECONDS.sleep(3);
// // 执行核心打印逻辑
// invokeFun("orderPrint", "java.order", req, (data) -> {
// JSONObject jsonObject = JSONObject.parseObject(data);
// String orderId = jsonObject.getString("orderId");
// if (orderId == null) {
// throw new RuntimeException("订单打印失败未传递orderId");
// }
// Boolean printOrder = jsonObject.getBoolean("printOrder");
// funUtil.runFunAndCheckKey(() -> {
// printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER);
// return null;
// }, RedisCst.getLockKey("orderPrint", orderId));
// });
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// // 记录中断日志
// log.warn("打印任务被中断req:{}", req, e);
// } catch (Exception e) {
// // 记录业务异常日志
// log.error("打印任务处理失败req:{}", req, e);
// }
// }, asyncExecutor);
}
/**