|
|
@ -27,6 +27,7 @@ import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
|
|
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@ -53,6 +54,12 @@ public class MqttConnectStatusListener implements IMqttConnectStatusListener, Sm
|
|
|
|
private MqttServerCreator serverCreator;
|
|
|
|
private MqttServerCreator serverCreator;
|
|
|
|
private MqttServerTemplate mqttServerTemplate;
|
|
|
|
private MqttServerTemplate mqttServerTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${broker.connectStatus.enable}")
|
|
|
|
|
|
|
|
private boolean publishConnectStatusEnable;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${broker.connectStatus.topic}")
|
|
|
|
|
|
|
|
private String publishConnectStatusTopic;
|
|
|
|
|
|
|
|
|
|
|
|
public MqttConnectStatusListener(ApplicationContext context, StringRedisTemplate redisTemplate) {
|
|
|
|
public MqttConnectStatusListener(ApplicationContext context, StringRedisTemplate redisTemplate) {
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
|
this.redisTemplate = redisTemplate;
|
|
|
@ -99,6 +106,7 @@ public class MqttConnectStatusListener implements IMqttConnectStatusListener, Sm
|
|
|
|
* @param connectStatus
|
|
|
|
* @param connectStatus
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void pushConnectStatus(String clientId, ConnectStatus connectStatus){
|
|
|
|
public void pushConnectStatus(String clientId, ConnectStatus connectStatus){
|
|
|
|
|
|
|
|
if(publishConnectStatusEnable){
|
|
|
|
Map<String,Object> entityMap = new HashMap<>();
|
|
|
|
Map<String,Object> entityMap = new HashMap<>();
|
|
|
|
entityMap.put("msg","设备设备连接状态信息");
|
|
|
|
entityMap.put("msg","设备设备连接状态信息");
|
|
|
|
entityMap.put("deviceType", DeviceType.edge.getKey());
|
|
|
|
entityMap.put("deviceType", DeviceType.edge.getKey());
|
|
|
@ -106,11 +114,15 @@ public class MqttConnectStatusListener implements IMqttConnectStatusListener, Sm
|
|
|
|
entityMap.put("connectStatus",connectStatus.getKey());
|
|
|
|
entityMap.put("connectStatus",connectStatus.getKey());
|
|
|
|
entityMap.put("statusTime",System.currentTimeMillis());
|
|
|
|
entityMap.put("statusTime",System.currentTimeMillis());
|
|
|
|
String jsonString = JSONArray.toJSONString(entityMap);
|
|
|
|
String jsonString = JSONArray.toJSONString(entityMap);
|
|
|
|
boolean result = mqttServerTemplate.publishAll("/device/status/v1", jsonString.getBytes(StandardCharsets.UTF_8));
|
|
|
|
boolean result = mqttServerTemplate.publishAll(publishConnectStatusTopic, jsonString.getBytes(StandardCharsets.UTF_8));
|
|
|
|
if(result){
|
|
|
|
if(result){
|
|
|
|
logger.info("客户端:"+clientId+";"+ (connectStatus == ConnectStatus.connct ? "连接" :"断开") +"状态推送成功");
|
|
|
|
logger.info("客户端:"+clientId+";"+ (connectStatus == ConnectStatus.connct ? "连接" :"断开") +"状态推送成功");
|
|
|
|
}else {
|
|
|
|
}else {
|
|
|
|
logger.info("客户端:"+clientId+";"+ (connectStatus == ConnectStatus.connct ? "连接" :"断开") +"状态推送失败");
|
|
|
|
logger.info("客户端:"+clientId+";"+ (connectStatus == ConnectStatus.connct ? "连接" :"断开") +"状态推送失败");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
logger.info("未开启设备连接状态推送");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|