|
@ -1,6 +1,8 @@
|
|
|
package com.yihu.jw.care.util;
|
|
|
|
|
|
import com.yihu.jw.care.dao.device.BaseMqttCallbackRecordDao;
|
|
|
import com.yihu.jw.entity.care.device.BaseMqttCallbackRecordDO;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
|
import org.slf4j.Logger;
|
|
@ -139,16 +141,16 @@ public class MQTTKXClientUtil {
|
|
|
public void messageArrived(String topic, MqttMessage message) throws Exception {
|
|
|
logger.info("接收消息主题 : " + topic+","+"接收消息内容 : " + new String(message.getPayload()));
|
|
|
// subscribe后得到的消息会执行到这里面
|
|
|
// BaseMqttCallbackRecordDO mqttCallbackRecordDO = new BaseMqttCallbackRecordDO();
|
|
|
// if(StringUtils.isNotBlank(topic)){
|
|
|
// String[] deviceId = topic.split("//");
|
|
|
// if(deviceId.length>1){
|
|
|
// mqttCallbackRecordDO.setDeviceId(deviceId[1]);
|
|
|
// }
|
|
|
// }
|
|
|
// mqttCallbackRecordDO.setTopic(topic);
|
|
|
// mqttCallbackRecordDO.setPayload(new String(message.getPayload()));
|
|
|
// mqttCallbackRecordDao.save(mqttCallbackRecordDO);
|
|
|
BaseMqttCallbackRecordDO mqttCallbackRecordDO = new BaseMqttCallbackRecordDO();
|
|
|
if(StringUtils.isNotBlank(topic)){
|
|
|
String[] deviceId = topic.split("//");
|
|
|
if(deviceId.length>1){
|
|
|
mqttCallbackRecordDO.setDeviceId(deviceId[1]);
|
|
|
}
|
|
|
}
|
|
|
mqttCallbackRecordDO.setTopic(topic);
|
|
|
mqttCallbackRecordDO.setPayload(new String(message.getPayload()));
|
|
|
mqttCallbackRecordDao.save(mqttCallbackRecordDO);
|
|
|
}
|
|
|
|
|
|
@Override
|