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 122 */
123 123 public static final String VM_MSG_SUBSCRIBE_ALARM = "alarm";
124 124  
  125 +
125 126 /**
126 127 * 报警通知的发送 (收到redis发出的通知,转发给其他平台)
127 128 */
... ...
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
... ... @@ -52,6 +52,8 @@ public class UserSetting {
52 52  
53 53 private Boolean refuseChannelStatusChannelFormNotify = Boolean.FALSE;
54 54  
  55 + private Boolean deviceStatusNotify = Boolean.FALSE;
  56 +
55 57 private String serverId = "000000";
56 58  
57 59 private String recordPath = null;
... ... @@ -267,4 +269,12 @@ public class UserSetting {
267 269 public void setMaxNotifyCountQueue(int maxNotifyCountQueue) {
268 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 108 if (updateChannelOnlineList.size() > 300) {
109 109 executeSaveForOnline();
110 110 }
  111 + if (userSetting.getDeviceStatusNotify()) {
  112 + // 发送redis消息
  113 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), true);
  114 + }
  115 +
111 116 break;
112 117 case CatalogEvent.OFF :
113 118 // 离线
... ... @@ -117,6 +122,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
117 122 if (updateChannelOfflineList.size() > 300) {
118 123 executeSaveForOffline();
119 124 }
  125 + if (userSetting.getDeviceStatusNotify()) {
  126 + // 发送redis消息
  127 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  128 + }
120 129 }else {
121 130 logger.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
122 131 }
... ... @@ -129,6 +138,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
129 138 if (updateChannelOfflineList.size() > 300) {
130 139 executeSaveForOffline();
131 140 }
  141 + if (userSetting.getDeviceStatusNotify()) {
  142 + // 发送redis消息
  143 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  144 + }
132 145 }else {
133 146 logger.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
134 147 }
... ... @@ -141,6 +154,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
141 154 if (updateChannelOfflineList.size() > 300) {
142 155 executeSaveForOffline();
143 156 }
  157 + if (userSetting.getDeviceStatusNotify()) {
  158 + // 发送redis消息
  159 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
  160 + }
144 161 }else {
145 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 165 String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
166 166 // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线
167 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 175 @Override
... ... @@ -193,6 +198,11 @@ public class DeviceServiceImpl implements IDeviceService {
193 198 // 移除订阅
194 199 removeCatalogSubscribe(device);
195 200 removeMobilePositionSubscribe(device);
  201 + if (userSetting.getDeviceStatusNotify()) {
  202 + // 发送redis消息
  203 + redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false);
  204 + }
  205 +
196 206 }
197 207  
198 208 @Override
... ...
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
... ... @@ -261,4 +261,6 @@ public interface IRedisCatchStorage {
261 261 List<Device> getAllDevices();
262 262  
263 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 902 + userSetting.getServerId() + "_*_" + id + "_*";
903 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 180 refuse-channel-status-channel-form-notify: false
181 181 # 设置notify缓存队列最大长度,超过此长度的数据将返回486 BUSY_HERE,消息丢弃, 默认10000
182 182 max-notify-count-queue: 10000
  183 + # 设备/通道状态变化时发送消息
  184 + device-status-notify: false
183 185 # 跨域配置,配置你访问前端页面的地址即可, 可以配置多个
184 186 allowed-origins:
185 187 - http://localhost:8008
... ...