|
@@ -75,23 +75,26 @@ public class MqttConfig {
|
|
|
|
|
|
@Override
|
|
|
public void messageArrived(String topic, MqttMessage message) {
|
|
|
- String payload = new String(message.getPayload());
|
|
|
- // 如果是上下线消息
|
|
|
- if (topic.contains("connected")) {
|
|
|
- topic = topic.substring(topic.lastIndexOf("/") + 1);
|
|
|
- }
|
|
|
- // 将消息转发到处理逻辑
|
|
|
- handleIncomingMessage(topic, payload);
|
|
|
-
|
|
|
- // 如果不是上下线消息
|
|
|
- if (!topic.contains("connected")) {
|
|
|
- MqttMsg mqttMsg = new MqttMsg();
|
|
|
- mqttMsg.setCreateDate(new Date());
|
|
|
- mqttMsg.setTopic(topic);
|
|
|
- mqttMsg.setMessage(payload);
|
|
|
- mqttMsgService.save(mqttMsg);
|
|
|
+ try {
|
|
|
+ String payload = new String(message.getPayload());
|
|
|
+ // 如果是上下线消息
|
|
|
+ if (topic.contains("connected")) {
|
|
|
+ topic = topic.substring(topic.lastIndexOf("/") + 1);
|
|
|
+ }
|
|
|
+ // 将消息转发到处理逻辑
|
|
|
+ handleIncomingMessage(topic, payload);
|
|
|
+
|
|
|
+ // 如果不是上下线消息
|
|
|
+ if (!topic.contains("connected")) {
|
|
|
+ MqttMsg mqttMsg = new MqttMsg();
|
|
|
+ mqttMsg.setCreateDate(new Date());
|
|
|
+ mqttMsg.setTopic(topic);
|
|
|
+ mqttMsg.setMessage(payload);
|
|
|
+ mqttMsgService.save(mqttMsg);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("--处理消息失败:{}", e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|