Commit 82ab6b1760b8787e31bed4020a0831c64fa05077

Authored by 648540858
1 parent eb177a67

去除jedis,方便支持redis集群

@@ -61,13 +61,6 @@ @@ -61,13 +61,6 @@
61 <dependency> 61 <dependency>
62 <groupId>org.springframework.boot</groupId> 62 <groupId>org.springframework.boot</groupId>
63 <artifactId>spring-boot-starter-data-redis</artifactId> 63 <artifactId>spring-boot-starter-data-redis</artifactId>
64 - <exclusions>  
65 - <!-- 去掉 Lettuce 的依赖, Spring Boot 优先使用 Lettuce 作为 Redis 客户端 -->  
66 - <exclusion>  
67 - <groupId>io.lettuce</groupId>  
68 - <artifactId>lettuce-core</artifactId>  
69 - </exclusion>  
70 - </exclusions>  
71 </dependency> 64 </dependency>
72 <dependency> 65 <dependency>
73 <groupId>org.springframework.boot</groupId> 66 <groupId>org.springframework.boot</groupId>
@@ -94,11 +87,6 @@ @@ -94,11 +87,6 @@
94 <artifactId>spring-boot-starter-security</artifactId> 87 <artifactId>spring-boot-starter-security</artifactId>
95 </dependency> 88 </dependency>
96 89
97 - <dependency>  
98 - <groupId>redis.clients</groupId>  
99 - <artifactId>jedis</artifactId>  
100 - </dependency>  
101 -  
102 <!-- druid数据库连接池 --> 90 <!-- druid数据库连接池 -->
103 <dependency> 91 <dependency>
104 <groupId>com.alibaba</groupId> 92 <groupId>com.alibaba</groupId>
src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
1 package com.genersoft.iot.vmp.conf; 1 package com.genersoft.iot.vmp.conf;
2 2
  3 +import com.alibaba.fastjson.parser.ParserConfig;
3 import com.genersoft.iot.vmp.common.VideoManagerConstants; 4 import com.genersoft.iot.vmp.common.VideoManagerConstants;
4 import com.genersoft.iot.vmp.service.impl.*; 5 import com.genersoft.iot.vmp.service.impl.*;
5 import org.apache.commons.lang3.StringUtils; 6 import org.apache.commons.lang3.StringUtils;
@@ -9,15 +10,14 @@ import org.springframework.cache.annotation.CachingConfigurerSupport; @@ -9,15 +10,14 @@ import org.springframework.cache.annotation.CachingConfigurerSupport;
9 import org.springframework.context.annotation.Bean; 10 import org.springframework.context.annotation.Bean;
10 import org.springframework.context.annotation.Configuration; 11 import org.springframework.context.annotation.Configuration;
11 import org.springframework.data.redis.connection.RedisConnectionFactory; 12 import org.springframework.data.redis.connection.RedisConnectionFactory;
  13 +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
12 import org.springframework.data.redis.core.RedisTemplate; 14 import org.springframework.data.redis.core.RedisTemplate;
13 import org.springframework.data.redis.listener.PatternTopic; 15 import org.springframework.data.redis.listener.PatternTopic;
14 import org.springframework.data.redis.listener.RedisMessageListenerContainer; 16 import org.springframework.data.redis.listener.RedisMessageListenerContainer;
15 import org.springframework.data.redis.serializer.StringRedisSerializer; 17 import org.springframework.data.redis.serializer.StringRedisSerializer;
16 18
17 -import com.alibaba.fastjson.parser.ParserConfig;  
18 import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; 19 import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer;
19 -import redis.clients.jedis.JedisPool;  
20 -import redis.clients.jedis.JedisPoolConfig; 20 +
21 21
22 /** 22 /**
23 * @description:Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置 23 * @description:Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置
@@ -28,23 +28,6 @@ import redis.clients.jedis.JedisPoolConfig; @@ -28,23 +28,6 @@ import redis.clients.jedis.JedisPoolConfig;
28 @Configuration 28 @Configuration
29 public class RedisConfig extends CachingConfigurerSupport { 29 public class RedisConfig extends CachingConfigurerSupport {
30 30
31 - @Value("${spring.redis.host}")  
32 - private String host;  
33 - @Value("${spring.redis.port}")  
34 - private int port;  
35 - @Value("${spring.redis.database}")  
36 - private int database;  
37 - @Value("${spring.redis.password}")  
38 - private String password;  
39 - @Value("${spring.redis.timeout}")  
40 - private int timeout;  
41 - @Value("${spring.redis.poolMaxTotal:1000}")  
42 - private int poolMaxTotal;  
43 - @Value("${spring.redis.poolMaxIdle:500}")  
44 - private int poolMaxIdle;  
45 - @Value("${spring.redis.poolMaxWait:5}")  
46 - private int poolMaxWait;  
47 -  
48 @Autowired 31 @Autowired
49 private RedisGpsMsgListener redisGPSMsgListener; 32 private RedisGpsMsgListener redisGPSMsgListener;
50 33
@@ -61,37 +44,25 @@ public class RedisConfig extends CachingConfigurerSupport { @@ -61,37 +44,25 @@ public class RedisConfig extends CachingConfigurerSupport {
61 private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; 44 private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener;
62 45
63 @Bean 46 @Bean
64 - public JedisPool jedisPool() {  
65 - if (StringUtils.isBlank(password)) {  
66 - password = null;  
67 - }  
68 - JedisPoolConfig poolConfig = new JedisPoolConfig();  
69 - poolConfig.setMaxIdle(poolMaxIdle);  
70 - poolConfig.setMaxTotal(poolMaxTotal);  
71 - // 秒转毫秒  
72 - poolConfig.setMaxWaitMillis(poolMaxWait * 1000L);  
73 - JedisPool jp = new JedisPool(poolConfig, host, port, timeout * 1000, password, database);  
74 - return jp;  
75 - }  
76 -  
77 - @Bean("redisTemplate")  
78 public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { 47 public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
79 - RedisTemplate<Object, Object> template = new RedisTemplate<>();  
80 - template.setConnectionFactory(redisConnectionFactory);  
81 - // 使用fastjson进行序列化处理,提高解析效率  
82 - FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class); 48 + RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
  49 + // 使用fastJson序列化
  50 + FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
83 // value值的序列化采用fastJsonRedisSerializer 51 // value值的序列化采用fastJsonRedisSerializer
84 - template.setValueSerializer(serializer);  
85 - template.setHashValueSerializer(serializer); 52 + redisTemplate.setValueSerializer(fastJsonRedisSerializer);
  53 + redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
  54 + // 全局开启AutoType,不建议使用
  55 + ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
  56 + // 建议使用这种方式,小范围指定白名单,需要序列化的类
  57 +// ParserConfig.getGlobalInstance().addAccept("com.avatar");
86 // key的序列化采用StringRedisSerializer 58 // key的序列化采用StringRedisSerializer
87 - template.setKeySerializer(new StringRedisSerializer());  
88 - template.setHashKeySerializer(new StringRedisSerializer());  
89 - template.setConnectionFactory(redisConnectionFactory);  
90 - // 使用fastjson时需设置此项,否则会报异常not support type  
91 - ParserConfig.getGlobalInstance().setAutoTypeSupport(true);  
92 - return template; 59 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  60 + redisTemplate.setHashKeySerializer(new StringRedisSerializer());
  61 + redisTemplate.setConnectionFactory(redisConnectionFactory);
  62 + return redisTemplate;
93 } 63 }
94 64
  65 +
95 /** 66 /**
96 * redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器 67 * redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
97 * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理 68 * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理
src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java
@@ -28,7 +28,7 @@ public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMe @@ -28,7 +28,7 @@ public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMe
28 RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection(); 28 RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection();
29 Properties config = connection.getConfig("notify-keyspace-events"); 29 Properties config = connection.getConfig("notify-keyspace-events");
30 try { 30 try {
31 - if (!config.getProperty("notify-keyspace-events").equals(keyspaceNotificationsConfigParameter)) { 31 + if (!keyspaceNotificationsConfigParameter.equals(config.getProperty("notify-keyspace-events"))) {
32 connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); 32 connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
33 } 33 }
34 } finally { 34 } finally {
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -445,12 +445,15 @@ public class ZLMHttpHookListener { @@ -445,12 +445,15 @@ public class ZLMHttpHookListener {
445 if (streamInfo!=null){ 445 if (streamInfo!=null){
446 redisCatchStorage.stopPlay(streamInfo); 446 redisCatchStorage.stopPlay(streamInfo);
447 storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); 447 storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
  448 + // 如果正在给上级推送,则发送bye
  449 +
448 }else{ 450 }else{
449 streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null); 451 streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
450 if (streamInfo != null) { 452 if (streamInfo != null) {
451 redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(), 453 redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
452 streamInfo.getStream(), null); 454 streamInfo.getStream(), null);
453 } 455 }
  456 + // 如果正在给上级推送,则发送bye
454 } 457 }
455 }else { 458 }else {
456 if (!"rtp".equals(app)){ 459 if (!"rtp".equals(app)){
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -36,7 +36,6 @@ import com.genersoft.iot.vmp.service.IMediaServerService; @@ -36,7 +36,6 @@ import com.genersoft.iot.vmp.service.IMediaServerService;
36 import com.genersoft.iot.vmp.service.bean.SSRCInfo; 36 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
37 import com.genersoft.iot.vmp.storager.dao.MediaServerMapper; 37 import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
38 import com.genersoft.iot.vmp.utils.DateUtil; 38 import com.genersoft.iot.vmp.utils.DateUtil;
39 -import com.genersoft.iot.vmp.utils.redis.JedisUtil;  
40 import com.genersoft.iot.vmp.utils.redis.RedisUtil; 39 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
41 import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 40 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
42 41
@@ -91,9 +90,6 @@ public class MediaServerServiceImpl implements IMediaServerService { @@ -91,9 +90,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
91 @Autowired 90 @Autowired
92 private EventPublisher publisher; 91 private EventPublisher publisher;
93 92
94 - @Autowired  
95 - JedisUtil jedisUtil;  
96 -  
97 /** 93 /**
98 * 初始化 94 * 初始化
99 */ 95 */
src/main/java/com/genersoft/iot/vmp/utils/redis/JedisUtil.java deleted 100644 → 0
1 -package com.genersoft.iot.vmp.utils.redis;  
2 -  
3 -import org.springframework.beans.factory.annotation.Autowired;  
4 -import org.springframework.stereotype.Component;  
5 -import redis.clients.jedis.Jedis;  
6 -import redis.clients.jedis.JedisPool;  
7 -  
8 -import java.util.Set;  
9 -  
10 -/**  
11 - * @description:Jedis工具类  
12 - * @author: wangshaopeng@sunnybs.com  
13 - * @date: 2021年03月22日 下午8:27:29  
14 - */  
15 -@Component  
16 -public class JedisUtil {  
17 -  
18 - @Autowired  
19 - private JedisPool jedisPool;  
20 -  
21 - // ============================== Key ==============================  
22 -  
23 - /**  
24 - * 检查给定 key 是否存在。  
25 - *  
26 - * @param key  
27 - * @return  
28 - */  
29 - public Boolean exists(String key) {  
30 - Jedis jedis = null;  
31 - try {  
32 - jedis = jedisPool.getResource();  
33 - Boolean exists = jedis.exists(key);  
34 - return exists;  
35 - } finally {  
36 - returnToPool(jedis);  
37 - }  
38 - }  
39 -  
40 -  
41 - // ============================== Set ==============================  
42 -  
43 - /**  
44 - * SADD key member [member ...]  
45 - * 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。  
46 - * 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。  
47 - * 当 key 不是集合类型时,返回一个错误。  
48 - */  
49 - public Long sadd(String key, String... members) {  
50 - Jedis jedis = null;  
51 - try {  
52 - jedis = jedisPool.getResource();  
53 - Long smove = jedis.sadd(key, members);  
54 - return smove;  
55 - } finally {  
56 - returnToPool(jedis);  
57 - }  
58 - }  
59 -  
60 - /**  
61 - * SMEMBERS key  
62 - * 返回集合 key 中的所有成员。  
63 - * 不存在的 key 被视为空集合。  
64 - */  
65 - public Set<String> smembers(String key) {  
66 - Jedis jedis = null;  
67 - try {  
68 - jedis = jedisPool.getResource();  
69 - Set<String> smembers = jedis.smembers(key);  
70 - return smembers;  
71 - } finally {  
72 - returnToPool(jedis);  
73 - }  
74 - }  
75 -  
76 -  
77 - /**  
78 - * SREM key member1 [member2]  
79 - * 移除集合中一个或多个成员  
80 - */  
81 - public Long srem(String key, String... member) {  
82 - Jedis jedis = null;  
83 - try {  
84 - jedis = jedisPool.getResource();  
85 - Long srem = jedis.srem(key, member);  
86 - return srem;  
87 - } finally {  
88 - returnToPool(jedis);  
89 - }  
90 - }  
91 -  
92 - private void returnToPool(Jedis jedis) {  
93 - if (jedis != null) {  
94 - jedis.close();  
95 - }  
96 - }  
97 -}  
98 \ No newline at end of file 0 \ No newline at end of file
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -148,6 +148,8 @@ public class PlayController { @@ -148,6 +148,8 @@ public class PlayController {
148 // 超时处理 148 // 超时处理
149 result.onTimeout(()->{ 149 result.onTimeout(()->{
150 logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId)); 150 logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId));
  151 + redisCatchStorage.stopPlay(streamInfo);
  152 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
151 RequestMessage msg = new RequestMessage(); 153 RequestMessage msg = new RequestMessage();
152 msg.setId(uuid); 154 msg.setId(uuid);
153 msg.setKey(key); 155 msg.setKey(key);