循环依赖问题,太难搞了,fix bug
This commit is contained in:
parent
3ea6cf91a2
commit
66374e858d
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
package com.suisung.mall.shop.order.listener;
|
package com.suisung.mall.shop.order.listener;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import com.rabbitmq.client.Channel;
|
import com.rabbitmq.client.Channel;
|
||||||
import com.suisung.mall.common.constant.CommonConstant;
|
import com.suisung.mall.common.constant.CommonConstant;
|
||||||
@ -53,7 +54,6 @@ public class DelayMessageReceiver {
|
|||||||
processDeadMessage(message, channel, msg);
|
processDeadMessage(message, channel, msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理过期消息时发生异常,消息将重新入队,消息内容: {}", message, e);
|
log.error("处理过期消息时发生异常,消息将重新入队,消息内容: {}", message, e);
|
||||||
rejectMessage(channel, msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +69,7 @@ public class DelayMessageReceiver {
|
|||||||
// 检查消息是否为空
|
// 检查消息是否为空
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
log.warn("收到空消息,无法处理");
|
log.warn("收到空消息,无法处理");
|
||||||
|
ackMessage(channel, msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +85,12 @@ public class DelayMessageReceiver {
|
|||||||
// 根据消息分类处理不同类型的消息
|
// 根据消息分类处理不同类型的消息
|
||||||
if (category == MqConstant.DEAD_EVENT_CATE_ORDER_EXPIRED) {
|
if (category == MqConstant.DEAD_EVENT_CATE_ORDER_EXPIRED) {
|
||||||
// 处理订单超时消息
|
// 处理订单超时消息
|
||||||
return handleOrderExpiredMessage(message, channel, msg);
|
handleOrderExpiredMessage(message, channel, msg);
|
||||||
|
return true;
|
||||||
} else if (category == MqConstant.DEAD_EVENT_CATE_PRE_ORDER) {
|
} else if (category == MqConstant.DEAD_EVENT_CATE_PRE_ORDER) {
|
||||||
// 处理预订单消息
|
// 处理预订单消息
|
||||||
return handlePreOrderMessage(message);
|
handlePreOrderMessage(message);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
log.warn("未知的消息分类: {},消息内容: {}", category, message);
|
log.warn("未知的消息分类: {},消息内容: {}", category, message);
|
||||||
ackMessage(channel, msg);
|
ackMessage(channel, msg);
|
||||||
@ -106,12 +109,19 @@ public class DelayMessageReceiver {
|
|||||||
* @param message 消息内容
|
* @param message 消息内容
|
||||||
* @return 处理结果
|
* @return 处理结果
|
||||||
*/
|
*/
|
||||||
private boolean handleOrderExpiredMessage(JSONObject message, Channel channel, Message msg) {
|
private void handleOrderExpiredMessage(JSONObject message, Channel channel, Message msg) {
|
||||||
try {
|
try {
|
||||||
String orderId = message.getStr("orderId");
|
String orderId = message.getStr("orderId");
|
||||||
Integer storeId = message.getInt("storeId");
|
Integer storeId = message.getInt("storeId");
|
||||||
|
String title = message.getStr("title");
|
||||||
|
String content = message.getStr("message");
|
||||||
|
|
||||||
log.info("处理订单超时消息,订单号: {}, 店铺ID: {}", orderId, storeId);
|
if (StrUtil.isBlank(title)) {
|
||||||
|
title = "有一笔已超时的订单!";
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(content)) {
|
||||||
|
content = "您有一笔已超时的订单[" + orderId + "],请及时处理。"; // 消息内容
|
||||||
|
}
|
||||||
|
|
||||||
// 构造推送消息内容
|
// 构造推送消息内容
|
||||||
JSONObject payload = new JSONObject();
|
JSONObject payload = new JSONObject();
|
||||||
@ -120,16 +130,14 @@ public class DelayMessageReceiver {
|
|||||||
|
|
||||||
// 发送推送消息给商家员工
|
// 发送推送消息给商家员工
|
||||||
pushMessageService.noticeMerchantEmployeeOrderAction(
|
pushMessageService.noticeMerchantEmployeeOrderAction(
|
||||||
storeId, orderId, message.getStr("title"),
|
storeId, orderId, title,
|
||||||
message.getStr("message"), payload);
|
content, payload);
|
||||||
|
|
||||||
log.info("订单超时消息处理完成,订单号: {}, 店铺ID: {}", orderId, storeId);
|
log.info("订单超时消息处理完成,订单号: {}, 店铺ID: {}", orderId, storeId);
|
||||||
ackMessage(channel, msg);
|
ackMessage(channel, msg);
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理订单超时消息时发生异常,消息内容: {}", message, e);
|
log.error("处理订单超时消息时发生异常,消息内容: {}", message, e);
|
||||||
ackMessage(channel, msg);
|
ackMessage(channel, msg);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,7 +146,6 @@ public class OrderPayedListener {
|
|||||||
jsonObject.put("storeId", orderInfoOld.getStore_id()); // 店铺ID
|
jsonObject.put("storeId", orderInfoOld.getStore_id()); // 店铺ID
|
||||||
jsonObject.put("title", "有一笔已超时的订单!"); // 消息标题
|
jsonObject.put("title", "有一笔已超时的订单!"); // 消息标题
|
||||||
jsonObject.put("message", "您有一笔已超时的订单[" + orderId + "],请及时处理。"); // 消息内容
|
jsonObject.put("message", "您有一笔已超时的订单[" + orderId + "],请及时处理。"); // 消息内容
|
||||||
|
|
||||||
// 发送延迟消息
|
// 发送延迟消息
|
||||||
mqMessageService.sendDelayMessage(jsonObject.toString(), 1500L * 1000); // 转换为毫秒
|
mqMessageService.sendDelayMessage(jsonObject.toString(), 1500L * 1000); // 转换为毫秒
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user