优化数据推送

This commit is contained in:
zhanghan11 2024-08-13 09:38:54 +08:00
parent a2a41fc449
commit 577fb3d00d

View File

@ -64,6 +64,9 @@ public class IPCDataUploadSyncThread implements Runnable {
for (IpcMonitorField part : partList) { for (IpcMonitorField part : partList) {
// 筛选当前部位参数 // 筛选当前部位参数
List<IpcMonitorField> plcList = plcListRead.stream().filter(field -> part.getFieldCode().equals(field.getParentCode())).collect(Collectors.toList()); List<IpcMonitorField> plcList = plcListRead.stream().filter(field -> part.getFieldCode().equals(field.getParentCode())).collect(Collectors.toList());
if(plcList.isEmpty()){
continue;
}
// // 遍历生成振动数据 开始 // // 遍历生成振动数据 开始
// Map<String,String> tags = new HashMap<>(); // Map<String,String> tags = new HashMap<>();
// tags.put("part",part.getFieldValue()); // tags.put("part",part.getFieldValue());
@ -119,22 +122,20 @@ public class IPCDataUploadSyncThread implements Runnable {
} }
msgMap.put("d", dataList); msgMap.put("d", dataList);
// 进行数据推送 // 进行数据推送
// System.out.println(msgMap.toString()); MqttClient sampleClient = new MqttClient(host, clientId, new MemoryPersistence());
// System.out.println(host + "----------" + clientId + "----------" + topicu); MqttConnectOptions connOpts = new MqttConnectOptions();
// MqttClient sampleClient = new MqttClient(host, clientId, new MemoryPersistence()); connOpts.setUserName(userName);
// MqttConnectOptions connOpts = new MqttConnectOptions(); connOpts.setPassword(password.toCharArray());
// connOpts.setUserName(userName); sampleClient.connect(connOpts);
// connOpts.setPassword(password.toCharArray()); MqttMessage message = new MqttMessage(changeMapToByte(msgMap));
// sampleClient.connect(connOpts); sampleClient.publish(topicu, message);
// MqttMessage message = new MqttMessage(changeMapToByte(msgMap)); sampleClient.disconnect();
// sampleClient.publish(topicu, message); // 显式关闭MqttClient以释放资源
// sampleClient.disconnect(); sampleClient.close();
// // 显式关闭MqttClient以释放资源 logger.info("数据推送成功,时间{},数据{}", new Date(), msgMap.toString());
// sampleClient.close(); } catch (MqttException me) {
//// System.exit(0); logger.info("数据推送失败,时间{}reason{},msg{},loc{},cause{},excep{}", new Date(), me.getReasonCode(), me.getMessage(), me.getLocalizedMessage(), me.getCause(), me);
// } catch (MqttException me) { me.printStackTrace();
// logger.info("数据推送失败,时间{}reason{},msg{},loc{},cause{},excep{}", new Date(), me.getReasonCode(), me.getMessage(), me.getLocalizedMessage(), me.getCause(), me);
// me.printStackTrace();
} catch (Exception e) { } catch (Exception e) {
logger.info("数据推送失败,时间{}{}", new Date(), e.getMessage()); logger.info("数据推送失败,时间{}{}", new Date(), e.getMessage());
e.printStackTrace(); e.printStackTrace();