事务执行消息推送
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user