去除对redis key过期事件的使用;重构国标级联的注册保活

This commit is contained in:
648540858
2022-08-31 11:29:13 +08:00
parent d47902bdca
commit 2de4c322f6
45 changed files with 513 additions and 693 deletions

View File

@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.service.IPlatformService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,6 +16,7 @@ import java.util.List;
/**
* 系统启动时控制上级平台重新注册
* @author lin
*/
@Component
@Order(value=3)
@@ -27,7 +29,7 @@ public class SipPlatformRunner implements CommandLineRunner {
private IRedisCatchStorage redisCatchStorage;
@Autowired
private EventPublisher publisher;
private IPlatformService platformService;
@Autowired
private ISIPCommanderForPlatform sipCommanderForPlatform;
@@ -35,33 +37,26 @@ public class SipPlatformRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// 设置所有平台离线
storager.outlineForAllParentPlatform();
// 清理所有平台注册缓存
redisCatchStorage.cleanPlatformRegisterInfos();
// 停止所有推流
// zlmrtpServerFactory.closeAllSendRtpStream();
// 获取所有启用的平台
List<ParentPlatform> parentPlatforms = storager.queryEnableParentPlatformList(true);
for (ParentPlatform parentPlatform : parentPlatforms) {
redisCatchStorage.updatePlatformRegister(parentPlatform);
redisCatchStorage.updatePlatformKeepalive(parentPlatform);
// 更新缓存
ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
if (parentPlatform.isStatus()) {
// 设置所有平台离线
platformService.offline(parentPlatform);
// 取消订阅
sipCommanderForPlatform.unregister(parentPlatform, null, (eventResult)->{
platformService.login(parentPlatform);
});
}else {
platformService.login(parentPlatform);
}
// 取消订阅
sipCommanderForPlatform.unregister(parentPlatform, null, (eventResult)->{
// 发送平台未注册消息
publisher.platformNotRegisterEventPublish(parentPlatform.getServerGBId());
});
}
}
}

View File

@@ -31,8 +31,6 @@ public class UserSetting {
private Boolean logInDatebase = Boolean.TRUE;
private Boolean redisConfig = Boolean.TRUE;
private String serverId = "000000";
private String thirdPartyGBIdReg = "[\\s\\S]*";
@@ -123,14 +121,6 @@ public class UserSetting {
this.thirdPartyGBIdReg = thirdPartyGBIdReg;
}
public Boolean getRedisConfig() {
return redisConfig;
}
public void setRedisConfig(Boolean redisConfig) {
this.redisConfig = redisConfig;
}
public Boolean getRecordSip() {
return recordSip;
}

View File

@@ -1,41 +0,0 @@
package com.genersoft.iot.vmp.conf.redis;
import com.genersoft.iot.vmp.conf.UserSetting;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import java.util.Properties;
public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMessageListener {
private UserSetting userSetting;
private RedisMessageListenerContainer listenerContainer;
private String keyspaceNotificationsConfigParameter = "EA";
public RedisKeyExpirationEventMessageListener(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) {
super(listenerContainer);
this.listenerContainer = listenerContainer;
this.userSetting = userSetting;
}
@Override
public void init() {
if (!userSetting.getRedisConfig()) {
// 配置springboot默认Config为空即不让应用去修改redis的默认配置因为Redis服务出于安全会禁用CONFIG命令给远程用户使用
setKeyspaceNotificationsConfigParameter("");
}else {
RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection();
Properties config = connection.getConfig("notify-keyspace-events");
try {
if (!keyspaceNotificationsConfigParameter.equals(config.getProperty("notify-keyspace-events"))) {
connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
}
} finally {
connection.close();
}
}
super.init();
}
}