Commit 0c14970ab8755c698d4bbd57fab3f8001958d897

Authored by 648540858
1 parent 534be3f5

增加收到notify增加或移除通道时发送redis消息

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
... ... @@ -175,6 +175,11 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
175 175 }
176 176 }else {
177 177 addChannelMap.put(channel.getChannelId(), channel);
  178 + if (userSetting.getDeviceStatusNotify()) {
  179 + // 发送redis消息
  180 + redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true);
  181 + }
  182 +
178 183 if (addChannelMap.keySet().size() > 300) {
179 184 executeSaveForAdd();
180 185 }
... ... @@ -185,6 +190,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
185 190 // 删除
186 191 logger.info("[收到删除通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId());
187 192 deleteChannelList.add(channel);
  193 + if (userSetting.getDeviceStatusNotify()) {
  194 + // 发送redis消息
  195 + redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), false);
  196 + }
188 197 if (deleteChannelList.size() > 300) {
189 198 executeSaveForDelete();
190 199 }
... ... @@ -205,6 +214,10 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
205 214 if (addChannelMap.keySet().size() > 300) {
206 215 executeSaveForAdd();
207 216 }
  217 + if (userSetting.getDeviceStatusNotify()) {
  218 + // 发送redis消息
  219 + redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true);
  220 + }
208 221 }
209 222 break;
210 223 default:
... ...
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
... ... @@ -202,4 +202,5 @@ public interface IRedisCatchStorage {
202 202 void removeAllDevice();
203 203  
204 204 void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online);
  205 + void sendChannelAddOrDelete(String deviceId, String channelId, boolean add);
205 206 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
... ... @@ -611,4 +611,19 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
611 611 // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号
612 612 stringRedisTemplate.convertAndSend(key, msg.toString());
613 613 }
  614 +
  615 + @Override
  616 + public void sendChannelAddOrDelete(String deviceId, String channelId, boolean add) {
  617 + String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS;
  618 + logger.info("[redis通知] 推送通道{}, {}/{}", add?"增加":"移除", deviceId, channelId);
  619 +
  620 + StringBuilder msg = new StringBuilder();
  621 + msg.append(deviceId);
  622 + if (channelId != null) {
  623 + msg.append(":").append(channelId);
  624 + }
  625 + msg.append(" ").append(add? "ADD":"DELETE");
  626 + // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号
  627 + stringRedisTemplate.convertAndSend(key, msg.toString());
  628 + }
614 629 }
... ...