|
|
|
|
@ -59,11 +59,12 @@ public class HazardMqttMessageHandler implements MqttMessageHandler {
|
|
|
|
|
log.info("【危险源模块】接收到MQTT消息 - Topic: {}, QoS: {}, Retained: {}, Payload: {}",
|
|
|
|
|
topic, message.getQos(), message.isRetained(), payload);
|
|
|
|
|
|
|
|
|
|
// TODO: 根据不同的主题分发到不同的业务处理方法
|
|
|
|
|
if (topic.equals("iot_hazard_server")) {
|
|
|
|
|
handleHazardMessage(topic, payload);
|
|
|
|
|
} else if (topic.equals("status/online")){
|
|
|
|
|
handleOnlineMessage(topic, payload);
|
|
|
|
|
} else if (topic.equals("iot_hazard/warning")) {
|
|
|
|
|
handleWarningMessage(topic, payload);
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("未知的消息主题: {}", topic);
|
|
|
|
|
}
|
|
|
|
|
@ -102,6 +103,7 @@ public class HazardMqttMessageHandler implements MqttMessageHandler {
|
|
|
|
|
public void subscribeTopics() {
|
|
|
|
|
try {
|
|
|
|
|
// 订阅一个主题,QoS=1
|
|
|
|
|
mqttGateway.subscribe("iot_hazard/warning", 1);
|
|
|
|
|
mqttGateway.subscribe("iot_hazard_server", 1);
|
|
|
|
|
mqttGateway.subscribe("status/online", 1);
|
|
|
|
|
log.info("危险源模块已订阅MQTT主题: iot_hazard_server");
|
|
|
|
|
@ -195,4 +197,8 @@ public class HazardMqttMessageHandler implements MqttMessageHandler {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleWarningMessage(String topic, String payload) {
|
|
|
|
|
log.info("处理 告警 消息 - Topic: {}, Payload: {}", topic, payload);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|