key 过期

订单 超时 取消 定时任务
历史订单
订单取消 队列
redis 序列化
This commit is contained in:
2025-02-26 16:14:31 +08:00
parent 0674936901
commit b056d53e91
13 changed files with 191 additions and 44 deletions

View File

@@ -26,9 +26,14 @@ public class RabbitConfig {
// 设置消息过期时间为 180000 毫秒(即 180 秒)
args.put("x-message-ttl", 180000);
return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, args);
// return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, null);
}
@Bean
public Queue orderCancelQueue() {
return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_CANCEL_QUEUE, true);
}
@Bean
public Queue orderStockQueue() {
return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_STOCK_QUEUE, true);

View File

@@ -11,6 +11,7 @@ public interface RabbitConstants {
class Queue {
public static final String ORDER_STOCK_QUEUE = "order.stock.queue";
public static final String ORDER_CANCEL_QUEUE = "order.cancel.queue";
public static final String ORDER_PRINT_QUEUE = "order.print.queue";
}
}

View File

@@ -17,24 +17,35 @@ public class RabbitPublisher {
@Resource
private RabbitTemplate rabbitTemplate;
/**
* 订单取消消息
* 目前 用来回滚库存
* @param orderId 订单id
*/
public void sendOrderCancelMsg(String orderId) {
sendMsg(RabbitConstants.Queue.ORDER_STOCK_QUEUE, orderId);
}
/**
* 库存损耗消息
* @param orderId 订单id
*/
public void sendOrderStockMsg(String orderId) {
sendMsg(RabbitConstants.Exchange.CASH_EXCHANGE, RabbitConstants.Queue.ORDER_STOCK_QUEUE, orderId);
sendMsg(RabbitConstants.Queue.ORDER_STOCK_QUEUE, orderId);
}
/**
* 订单打印消息
* @param orderId
* @param orderId 订单id
*/
public void sendOrderPrintMsg(String orderId) {
sendMsg(RabbitConstants.Exchange.CASH_EXCHANGE, RabbitConstants.Queue.ORDER_PRINT_QUEUE, orderId);
sendMsg(RabbitConstants.Queue.ORDER_PRINT_QUEUE, orderId);
}
private void sendMsg(String exchange, String queue, String msg) {
rabbitTemplate.convertAndSend(activeProfile + "-" + exchange, activeProfile + "-" + queue, msg);
private void sendMsg(String queue, String msg) {
rabbitTemplate.convertAndSend(activeProfile + "-" + RabbitConstants.Exchange.CASH_EXCHANGE, activeProfile + "-" + queue, msg);
}
}