From 2166ec93624b6b9d2f5702d30b9f5030a37d72b5 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 08 十二月 2021 20:56:07 +0800 Subject: [PATCH] 解决Redis服务出于安全会禁用CONFIG命令后服务不可用的问题 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java | 34 +++++++++++++++++++++++++++------- 1 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java index 71df295..4315c8d 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRunner.java @@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.MediaConfig; +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IStreamProxyService; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +18,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; import java.util.*; @@ -37,7 +40,13 @@ private IStreamProxyService streamProxyService; @Autowired + private EventPublisher publisher; + + @Autowired private IMediaServerService mediaServerService; + + @Autowired + private IRedisCatchStorage redisCatchStorage; @Autowired private MediaConfig mediaConfig; @@ -70,8 +79,14 @@ } }); - // TODO 璁㈤槄 zlm淇濇椿浜嬩欢, 褰搝lm绂荤嚎鏃跺仛涓氬姟鐨勫鐞� - + // 璁㈤槄 zlm淇濇椿浜嬩欢, 褰搝lm绂荤嚎鏃跺仛涓氬姟鐨勫鐞� + hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_keepalive,null, + (MediaServerItem mediaServerItem, JSONObject response)->{ + String mediaServerId = response.getString("mediaServerId"); + if (mediaServerId !=null ) { + mediaServerService.updateMediaServerKeepalive(mediaServerId, response.getJSONObject("data")); + } + }); // 鑾峰彇zlm淇℃伅 logger.info("绛夊緟榛樿zlm鎺ュ叆..."); @@ -107,7 +122,7 @@ @Async public void connectZlmServer(MediaServerItem mediaServerItem){ - ZLMServerConfig zlmServerConfig = getMediaServerConfig(mediaServerItem); + ZLMServerConfig zlmServerConfig = getMediaServerConfig(mediaServerItem, 1); if (zlmServerConfig != null) { zlmServerConfig.setIp(mediaServerItem.getIp()); zlmServerConfig.setHttpPort(mediaServerItem.getHttpPort()); @@ -116,7 +131,7 @@ } } - public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem) { + public ZLMServerConfig getMediaServerConfig(MediaServerItem mediaServerItem, int index) { if (startGetMedia == null) { return null;} if (!mediaServerItem.isDefaultServer() && mediaServerService.getOne(mediaServerItem.getId()) == null) { return null; @@ -133,14 +148,19 @@ ZLMServerConfig.setIp(mediaServerItem.getIp()); } } else { - logger.error("[ {} ]-[ {}:{} ]涓诲姩杩炴帴澶辫触澶辫触, 2s鍚庨噸璇�", - mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort()); + logger.error("[ {} ]-[ {}:{} ]绗瑊}娆′富鍔ㄨ繛鎺ュけ璐�, 2s鍚庨噸璇�", + mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort(), index); + if (index == 1 && !StringUtils.isEmpty(mediaServerItem.getId())) { + logger.info("[ {} ]-[ {}:{} ]绗瑊}娆′富鍔ㄨ繛鎺ュけ璐�, 寮�濮嬫竻鐞嗙浉鍏宠祫婧�", + mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort(), index); + publisher.zlmOfflineEventPublish(mediaServerItem.getId()); + } try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } - ZLMServerConfig = getMediaServerConfig(mediaServerItem); + ZLMServerConfig = getMediaServerConfig(mediaServerItem, index += 1); } return ZLMServerConfig; -- Gitblit v1.8.0