diff --git a/pom.xml b/pom.xml index 41be5675..2abd9d8c 100644 --- a/pom.xml +++ b/pom.xml @@ -61,13 +61,6 @@ org.springframework.boot spring-boot-starter-data-redis - - - - io.lettuce - lettuce-core - - org.springframework.boot @@ -94,11 +87,6 @@ spring-boot-starter-security - - redis.clients - jedis - - com.alibaba diff --git a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java index 6a862ae3..d2e1347e 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.conf; +import com.alibaba.fastjson.parser.ParserConfig; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.service.impl.*; import org.apache.commons.lang3.StringUtils; @@ -9,15 +10,14 @@ import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; import org.springframework.data.redis.serializer.StringRedisSerializer; -import com.alibaba.fastjson.parser.ParserConfig; import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; + /** * @description:Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置 @@ -28,23 +28,6 @@ import redis.clients.jedis.JedisPoolConfig; @Configuration public class RedisConfig extends CachingConfigurerSupport { - @Value("${spring.redis.host}") - private String host; - @Value("${spring.redis.port}") - private int port; - @Value("${spring.redis.database}") - private int database; - @Value("${spring.redis.password}") - private String password; - @Value("${spring.redis.timeout}") - private int timeout; - @Value("${spring.redis.poolMaxTotal:1000}") - private int poolMaxTotal; - @Value("${spring.redis.poolMaxIdle:500}") - private int poolMaxIdle; - @Value("${spring.redis.poolMaxWait:5}") - private int poolMaxWait; - @Autowired private RedisGpsMsgListener redisGPSMsgListener; @@ -61,36 +44,24 @@ public class RedisConfig extends CachingConfigurerSupport { private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; @Bean - public JedisPool jedisPool() { - if (StringUtils.isBlank(password)) { - password = null; - } - JedisPoolConfig poolConfig = new JedisPoolConfig(); - poolConfig.setMaxIdle(poolMaxIdle); - poolConfig.setMaxTotal(poolMaxTotal); - // 秒转毫秒 - poolConfig.setMaxWaitMillis(poolMaxWait * 1000L); - JedisPool jp = new JedisPool(poolConfig, host, port, timeout * 1000, password, database); - return jp; + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + // 使用fastJson序列化 + FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class); + // value值的序列化采用fastJsonRedisSerializer + redisTemplate.setValueSerializer(fastJsonRedisSerializer); + redisTemplate.setHashValueSerializer(fastJsonRedisSerializer); + // 全局开启AutoType,不建议使用 + ParserConfig.getGlobalInstance().setAutoTypeSupport(true); + // 建议使用这种方式,小范围指定白名单,需要序列化的类 +// ParserConfig.getGlobalInstance().addAccept("com.avatar"); + // key的序列化采用StringRedisSerializer + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory); + return redisTemplate; } - @Bean("redisTemplate") - public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { - RedisTemplate template = new RedisTemplate<>(); - template.setConnectionFactory(redisConnectionFactory); - // 使用fastjson进行序列化处理,提高解析效率 - FastJsonRedisSerializer serializer = new FastJsonRedisSerializer(Object.class); - // value值的序列化采用fastJsonRedisSerializer - template.setValueSerializer(serializer); - template.setHashValueSerializer(serializer); - // key的序列化采用StringRedisSerializer - template.setKeySerializer(new StringRedisSerializer()); - template.setHashKeySerializer(new StringRedisSerializer()); - template.setConnectionFactory(redisConnectionFactory); - // 使用fastjson时需设置此项,否则会报异常not support type - ParserConfig.getGlobalInstance().setAutoTypeSupport(true); - return template; - } /** * redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器 diff --git a/src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java b/src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java index 18483800..ef4a6172 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java @@ -28,7 +28,7 @@ public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMe RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection(); Properties config = connection.getConfig("notify-keyspace-events"); try { - if (!config.getProperty("notify-keyspace-events").equals(keyspaceNotificationsConfigParameter)) { + if (!keyspaceNotificationsConfigParameter.equals(config.getProperty("notify-keyspace-events"))) { connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); } } finally { diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 0dc6bd38..57ad192f 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -445,12 +445,15 @@ public class ZLMHttpHookListener { if (streamInfo!=null){ redisCatchStorage.stopPlay(streamInfo); storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); + // 如果正在给上级推送,则发送bye + }else{ streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null); if (streamInfo != null) { redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(), streamInfo.getStream(), null); } + // 如果正在给上级推送,则发送bye } }else { if (!"rtp".equals(app)){ diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 59749189..aded98d5 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -36,7 +36,6 @@ import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.dao.MediaServerMapper; import com.genersoft.iot.vmp.utils.DateUtil; -import com.genersoft.iot.vmp.utils.redis.JedisUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; @@ -91,9 +90,6 @@ public class MediaServerServiceImpl implements IMediaServerService { @Autowired private EventPublisher publisher; - @Autowired - JedisUtil jedisUtil; - /** * 初始化 */ diff --git a/src/main/java/com/genersoft/iot/vmp/utils/redis/JedisUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/redis/JedisUtil.java deleted file mode 100644 index 1fb1d17e..00000000 --- a/src/main/java/com/genersoft/iot/vmp/utils/redis/JedisUtil.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.genersoft.iot.vmp.utils.redis; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; - -import java.util.Set; - -/** - * @description:Jedis工具类 - * @author: wangshaopeng@sunnybs.com - * @date: 2021年03月22日 下午8:27:29 - */ -@Component -public class JedisUtil { - - @Autowired - private JedisPool jedisPool; - - // ============================== Key ============================== - - /** - * 检查给定 key 是否存在。 - * - * @param key - * @return - */ - public Boolean exists(String key) { - Jedis jedis = null; - try { - jedis = jedisPool.getResource(); - Boolean exists = jedis.exists(key); - return exists; - } finally { - returnToPool(jedis); - } - } - - - // ============================== Set ============================== - - /** - * SADD key member [member ...] - * 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 - * 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 - * 当 key 不是集合类型时,返回一个错误。 - */ - public Long sadd(String key, String... members) { - Jedis jedis = null; - try { - jedis = jedisPool.getResource(); - Long smove = jedis.sadd(key, members); - return smove; - } finally { - returnToPool(jedis); - } - } - - /** - * SMEMBERS key - * 返回集合 key 中的所有成员。 - * 不存在的 key 被视为空集合。 - */ - public Set smembers(String key) { - Jedis jedis = null; - try { - jedis = jedisPool.getResource(); - Set smembers = jedis.smembers(key); - return smembers; - } finally { - returnToPool(jedis); - } - } - - - /** - * SREM key member1 [member2] - * 移除集合中一个或多个成员 - */ - public Long srem(String key, String... member) { - Jedis jedis = null; - try { - jedis = jedisPool.getResource(); - Long srem = jedis.srem(key, member); - return srem; - } finally { - returnToPool(jedis); - } - } - - private void returnToPool(Jedis jedis) { - if (jedis != null) { - jedis.close(); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java index db7f8fdc..cc6d4165 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java @@ -148,6 +148,8 @@ public class PlayController { // 超时处理 result.onTimeout(()->{ logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId)); + redisCatchStorage.stopPlay(streamInfo); + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key);