|
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.eclipse.paho.client.mqttv3.*;
|
|
|
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
|
|
+import org.jeecg.common.util.DateUtils;
|
|
|
import org.jeecg.modules.connConfig.configMqtt.entity.ConfigMqtt;
|
|
|
import org.jeecg.modules.connConfig.configMqtt.mapper.ConfigMqttMapper;
|
|
|
import org.jeecg.modules.push.dataPushConfig.entity.PointData;
|
|
@@ -29,7 +30,10 @@ public class MqttClientUtil implements ApplicationRunner {
|
|
|
@Autowired
|
|
|
private ConfigMqttMapper configMqttMapper;
|
|
|
|
|
|
- public MqttClient getMqttClient(ConfigMqtt configMqtt) throws MqttException {
|
|
|
+ public MqttClient getMqttClient(ConfigMqtt configMqttInfo) throws MqttException {
|
|
|
+
|
|
|
+ ConfigMqtt configMqtt = createDefaultMqttConfig();
|
|
|
+
|
|
|
MqttConnectOptions options = new MqttConnectOptions();
|
|
|
options.setUserName(configMqtt.getUsername());
|
|
|
options.setPassword(configMqtt.getPassword().toCharArray());
|
|
@@ -67,7 +71,8 @@ public class MqttClientUtil implements ApplicationRunner {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void sub(ConfigMqtt configMqtt) throws MqttException {
|
|
|
+ public void sub(ConfigMqtt configMqttInfo) throws MqttException {
|
|
|
+ ConfigMqtt configMqtt = createDefaultMqttConfig();
|
|
|
//创建mqtt连接url
|
|
|
StringBuffer url = new StringBuffer();
|
|
|
url.append("tcp://").append(configMqtt.getIp()).append(":").append(configMqtt.getHost());
|
|
@@ -122,6 +127,20 @@ public class MqttClientUtil implements ApplicationRunner {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 创建默认MQTT配置
|
|
|
+ private ConfigMqtt createDefaultMqttConfig() {
|
|
|
+ ConfigMqtt configMqtt = new ConfigMqtt();
|
|
|
+ // id添加时间戳
|
|
|
+ configMqtt.setId("186893" + DateUtils.date2Str(new Date(), DateUtils.yyyymmddhhmmss.get()));
|
|
|
+ configMqtt.setIp("127.0.0.1");
|
|
|
+ configMqtt.setHost("1883");
|
|
|
+ configMqtt.setUsername("admin");
|
|
|
+ configMqtt.setPassword("public");
|
|
|
+ configMqtt.setTopic("trace/performance/converter/add,trace/performance/billet/add,trace/billet/billetAssemblyNumber/add,syn/storageBill/add,syn/storageBill/update,syn/billetHotsendBase/shipp/depart");
|
|
|
+ configMqtt.setPushOrSub("1");
|
|
|
+ return configMqtt;
|
|
|
+ }
|
|
|
/**
|
|
|
* 发布消息
|
|
|
*
|