Commit 0f509049928733e49cd530d91f6463317e0c00ee

Authored by 648540858
1 parent c5653881

支持设备/通道状态变化时发送redis通知

src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -122,6 +122,7 @@ public class VideoManagerConstants { @@ -122,6 +122,7 @@ public class VideoManagerConstants {
122 */ 122 */
123 public static final String VM_MSG_SUBSCRIBE_ALARM = "alarm"; 123 public static final String VM_MSG_SUBSCRIBE_ALARM = "alarm";
124 124
  125 +
125 /** 126 /**
126 * 报警通知的发送 (收到redis发出的通知,转发给其他平台) 127 * 报警通知的发送 (收到redis发出的通知,转发给其他平台)
127 */ 128 */
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
@@ -52,6 +52,8 @@ public class UserSetting { @@ -52,6 +52,8 @@ public class UserSetting {
52 52
53 private Boolean refuseChannelStatusChannelFormNotify = Boolean.FALSE; 53 private Boolean refuseChannelStatusChannelFormNotify = Boolean.FALSE;
54 54
  55 + private Boolean deviceStatusNotify = Boolean.FALSE;
  56 +
55 private String serverId = "000000"; 57 private String serverId = "000000";
56 58
57 private String recordPath = null; 59 private String recordPath = null;
@@ -267,4 +269,12 @@ public class UserSetting { @@ -267,4 +269,12 @@ public class UserSetting {
267 public void setMaxNotifyCountQueue(int maxNotifyCountQueue) { 269 public void setMaxNotifyCountQueue(int maxNotifyCountQueue) {
268 this.maxNotifyCountQueue = maxNotifyCountQueue; 270 this.maxNotifyCountQueue = maxNotifyCountQueue;
269 } 271 }
  272 +
  273 + public Boolean getDeviceStatusNotify() {
  274 + return deviceStatusNotify;
  275 + }
  276 +
  277 + public void setDeviceStatusNotify(Boolean deviceStatusNotify) {
  278 + this.deviceStatusNotify = deviceStatusNotify;
  279 + }
270 } 280 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
@@ -108,6 +108,11 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @@ -108,6 +108,11 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
108 if (updateChannelOnlineList.size() > 300) { 108 if (updateChannelOnlineList.size() > 300) {
109 executeSaveForOnline(); 109 executeSaveForOnline();
110 } 110 }
  111 + if (userSetting.getDeviceStatusNotify()) {
  112 + // 发送redis消息
  113 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), true);
  114 + }
  115 +
111 break; 116 break;
112 case CatalogEvent.OFF : 117 case CatalogEvent.OFF :
113 // 离线 118 // 离线
@@ -117,6 +122,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @@ -117,6 +122,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
117 if (updateChannelOfflineList.size() > 300) { 122 if (updateChannelOfflineList.size() > 300) {
118 executeSaveForOffline(); 123 executeSaveForOffline();
119 } 124 }
  125 + if (userSetting.getDeviceStatusNotify()) {
  126 + // 发送redis消息
  127 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  128 + }
120 }else { 129 }else {
121 logger.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); 130 logger.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
122 } 131 }
@@ -129,6 +138,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @@ -129,6 +138,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
129 if (updateChannelOfflineList.size() > 300) { 138 if (updateChannelOfflineList.size() > 300) {
130 executeSaveForOffline(); 139 executeSaveForOffline();
131 } 140 }
  141 + if (userSetting.getDeviceStatusNotify()) {
  142 + // 发送redis消息
  143 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  144 + }
132 }else { 145 }else {
133 logger.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); 146 logger.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
134 } 147 }
@@ -141,6 +154,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent @@ -141,6 +154,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
141 if (updateChannelOfflineList.size() > 300) { 154 if (updateChannelOfflineList.size() > 300) {
142 executeSaveForOffline(); 155 executeSaveForOffline();
143 } 156 }
  157 + if (userSetting.getDeviceStatusNotify()) {
  158 + // 发送redis消息
  159 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  160 + }
144 }else { 161 }else {
145 logger.info("[收到通道视频故障通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); 162 logger.info("[收到通道视频故障通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
146 } 163 }
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -165,6 +165,11 @@ public class DeviceServiceImpl implements IDeviceService { @@ -165,6 +165,11 @@ public class DeviceServiceImpl implements IDeviceService {
165 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId(); 165 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
166 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线 166 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线
167 dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3); 167 dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId(), "首次注册后未能收到心跳"), device.getKeepaliveIntervalTime() * 1000 * 3);
  168 + if (userSetting.getDeviceStatusNotify()) {
  169 + // 发送redis消息
  170 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, true);
  171 + }
  172 +
168 } 173 }
169 174
170 @Override 175 @Override
@@ -193,6 +198,11 @@ public class DeviceServiceImpl implements IDeviceService { @@ -193,6 +198,11 @@ public class DeviceServiceImpl implements IDeviceService {
193 // 移除订阅 198 // 移除订阅
194 removeCatalogSubscribe(device); 199 removeCatalogSubscribe(device);
195 removeMobilePositionSubscribe(device); 200 removeMobilePositionSubscribe(device);
  201 + if (userSetting.getDeviceStatusNotify()) {
  202 + // 发送redis消息
  203 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false);
  204 + }
  205 +
196 } 206 }
197 207
198 @Override 208 @Override
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -261,4 +261,6 @@ public interface IRedisCatchStorage { @@ -261,4 +261,6 @@ public interface IRedisCatchStorage {
261 List<Device> getAllDevices(); 261 List<Device> getAllDevices();
262 262
263 void removeAllDevice(); 263 void removeAllDevice();
  264 +
  265 + void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online);
264 } 266 }
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -902,4 +902,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -902,4 +902,18 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
902 + userSetting.getServerId() + "_*_" + id + "_*"; 902 + userSetting.getServerId() + "_*_" + id + "_*";
903 return RedisUtil.scan(redisTemplate, key).size(); 903 return RedisUtil.scan(redisTemplate, key).size();
904 } 904 }
  905 +
  906 + @Override
  907 + public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) {
  908 + String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS;
  909 + logger.info("[redis通知] 推送设备/通道状态, {}/{}-{}", deviceId, channelId, online);
  910 + StringBuilder msg = new StringBuilder();
  911 + msg.append(deviceId);
  912 + if (channelId != null) {
  913 + msg.append(":").append(channelId);
  914 + }
  915 + msg.append(" ").append(online? "ON":"OFF");
  916 +
  917 + redisTemplate.convertAndSend(key, msg.toString());
  918 + }
905 } 919 }
src/main/resources/all-application.yml
@@ -180,6 +180,8 @@ user-settings: @@ -180,6 +180,8 @@ user-settings:
180 refuse-channel-status-channel-form-notify: false 180 refuse-channel-status-channel-form-notify: false
181 # 设置notify缓存队列最大长度,超过此长度的数据将返回486 BUSY_HERE,消息丢弃, 默认10000 181 # 设置notify缓存队列最大长度,超过此长度的数据将返回486 BUSY_HERE,消息丢弃, 默认10000
182 max-notify-count-queue: 10000 182 max-notify-count-queue: 10000
  183 + # 设备/通道状态变化时发送消息
  184 + device-status-notify: false
183 # 跨域配置,配置你访问前端页面的地址即可, 可以配置多个 185 # 跨域配置,配置你访问前端页面的地址即可, 可以配置多个
184 allowed-origins: 186 allowed-origins:
185 - http://localhost:8008 187 - http://localhost:8008