Просмотр исходного кода

去除jedis,方便支持redis集群

648540858 3 лет назад
Родитель
Сommit
82ab6b1760

+ 0 - 12
pom.xml

@@ -61,13 +61,6 @@
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-data-redis</artifactId>
-			 <exclusions>
-                <!-- 去掉  Lettuce 的依赖,  Spring Boot 优先使用 Lettuce 作为 Redis 客户端 -->
-                <exclusion>
-                    <groupId>io.lettuce</groupId>
-                    <artifactId>lettuce-core</artifactId>
-                </exclusion>
-            </exclusions>
 		</dependency>
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
@@ -94,11 +87,6 @@
 			<artifactId>spring-boot-starter-security</artifactId>
 		</dependency>
 
-		<dependency>
-			<groupId>redis.clients</groupId>
-			<artifactId>jedis</artifactId>
-		</dependency>
-
 		<!-- druid数据库连接池 -->
 		<dependency>
 			<groupId>com.alibaba</groupId>

+ 17 - 46
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,37 +44,25 @@ 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;
-	}
-
-	@Bean("redisTemplate")
 	public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
-		RedisTemplate<Object, Object> template = new RedisTemplate<>();
-		template.setConnectionFactory(redisConnectionFactory);
-		// 使用fastjson进行序列化处理,提高解析效率
-		FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class);
+		RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
+		// 使用fastJson序列化
+		FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
 		// value值的序列化采用fastJsonRedisSerializer
-		template.setValueSerializer(serializer);
-		template.setHashValueSerializer(serializer);
+		redisTemplate.setValueSerializer(fastJsonRedisSerializer);
+		redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
+		// 全局开启AutoType,不建议使用
+		 ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
+		// 建议使用这种方式,小范围指定白名单,需要序列化的类
+//		ParserConfig.getGlobalInstance().addAccept("com.avatar");
 		// key的序列化采用StringRedisSerializer
-		template.setKeySerializer(new StringRedisSerializer());
-		template.setHashKeySerializer(new StringRedisSerializer());
-		template.setConnectionFactory(redisConnectionFactory);
-		// 使用fastjson时需设置此项,否则会报异常not support type
-		ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
-		return template;
+		redisTemplate.setKeySerializer(new StringRedisSerializer());
+		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+		redisTemplate.setConnectionFactory(redisConnectionFactory);
+		return redisTemplate;
 	}
 
+
 	/**
 	 * redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
 	 * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理

+ 1 - 1
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 {

+ 3 - 0
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)){

+ 0 - 4
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;
-
     /**
      * 初始化
      */

+ 0 - 97
src/main/java/com/genersoft/iot/vmp/utils/redis/JedisUtil.java

@@ -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<String> smembers(String key) {
-        Jedis jedis = null;
-        try {
-            jedis = jedisPool.getResource();
-            Set<String> 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();
-        }
-    }
-}

+ 2 - 0
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);