This commit is contained in:
张成
2026-03-17 10:50:49 +08:00
parent f5082c157c
commit f071215ad5
3 changed files with 103 additions and 10 deletions

View File

@@ -13,6 +13,8 @@ class MqttDispatcher {
this.mqttClient = mqttClient;
this.actionHandlers = new Map();
this.subscribedTopics = new Set();
// 去重防抖:记录最近处理过的 Boss 消息 securityId -> timestamp
this.bossMessageDedupMap = new Map();
}
/**
@@ -345,6 +347,23 @@ class MqttDispatcher {
raw: payload
};
// 去重防抖:按 securityId或 cmid在一定时间窗口内只处理一次
const securityId = firstMsg && firstMsg.securityId;
const cmidObj = firstMsg && firstMsg.cmid;
const cmid = cmidObj && typeof cmidObj.low === 'number' ? `${cmidObj.high}:${cmidObj.low}` : null;
const dedupKey = securityId || cmid;
const now = Date.now();
const windowMs = 2 * 60 * 1000; // 2 分钟内视为重复
if (dedupKey) {
const lastTs = this.bossMessageDedupMap.get(dedupKey);
if (lastTs && now - lastTs < windowMs) {
console.log('[MQTT Boss 消息] 检测到重复消息,跳过处理:', { sn_code, dedupKey });
return;
}
this.bossMessageDedupMap.set(dedupKey, now);
}
console.log('[MQTT Boss 消息] 解析结果:', {
sn_code: normalized.sn_code,
type: normalized.type,