From 8f77d0c25cdd37d4cc96c923b46ae28607bae51d Mon Sep 17 00:00:00 2001
From: jiang <893224616@qq.com>
Date: 星期四, 18 八月 2022 16:17:23 +0800
Subject: [PATCH] 根据redis消息更新推流列表

---
 src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java |   67 +++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 17 deletions(-)

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 3448a2f..449a018 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
@@ -1,49 +1,76 @@
 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;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 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;
 
+
 /**
- * @Description:Redis涓棿浠堕厤缃被锛屼娇鐢╯pring-data-redis闆嗘垚锛岃嚜鍔ㄤ粠application.yml涓姞杞絩edis閰嶇疆
- * @author: songww
+ * @description:Redis涓棿浠堕厤缃被锛屼娇鐢╯pring-data-redis闆嗘垚锛岃嚜鍔ㄤ粠application.yml涓姞杞絩edis閰嶇疆
+ * @author: swwheihei
  * @date: 2019骞�5鏈�30鏃� 涓婂崍10:58:25
  * 
  */
 @Configuration
 public class RedisConfig extends CachingConfigurerSupport {
 
-	@Bean("redisTemplate")
+	@Autowired
+	private RedisGpsMsgListener redisGPSMsgListener;
+
+	@Autowired
+	private RedisAlarmMsgListener redisAlarmMsgListener;
+
+	@Autowired
+	private RedisStreamMsgListener redisStreamMsgListener;
+
+	@Autowired
+	private RedisGbPlayMsgListener redisGbPlayMsgListener;
+
+	@Autowired
+	private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener;
+
+	@Autowired
+	private RedisPushStreamListMsgListener redisPushStreamListMsgListener;
+
+	@Bean
 	public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
-		RedisTemplate<Object, Object> template = new RedisTemplate<>();
-		template.setConnectionFactory(redisConnectionFactory);
-		// 浣跨敤fastjson杩涜搴忓垪鍖栧鐞嗭紝鎻愰珮瑙f瀽鏁堢巼
-		FastJsonRedisSerializer<Object> serializer = new FastJsonRedisSerializer<Object>(Object.class);
+		RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
+		// 浣跨敤fastJson搴忓垪鍖�
+		FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
 		// value鍊肩殑搴忓垪鍖栭噰鐢╢astJsonRedisSerializer
-		template.setValueSerializer(serializer);
-		template.setHashValueSerializer(serializer);
+		redisTemplate.setValueSerializer(fastJsonRedisSerializer);
+		redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
+		// 鍏ㄥ眬寮�鍚疉utoType锛屼笉寤鸿浣跨敤
+		 ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
+		// 寤鸿浣跨敤杩欑鏂瑰紡锛屽皬鑼冨洿鎸囧畾鐧藉悕鍗曪紝闇�瑕佸簭鍒楀寲鐨勭被
+//		ParserConfig.getGlobalInstance().addAccept("com.avatar");
 		// key鐨勫簭鍒楀寲閲囩敤StringRedisSerializer
-		template.setKeySerializer(new StringRedisSerializer());
-		template.setHashKeySerializer(new StringRedisSerializer());
-		template.setConnectionFactory(redisConnectionFactory);
-		// 浣跨敤fastjson鏃堕渶璁剧疆姝ら」锛屽惁鍒欎細鎶ュ紓甯竛ot support type
-		ParserConfig.getGlobalInstance().setAutoTypeSupport(true); 
-		return template;
+		redisTemplate.setKeySerializer(new StringRedisSerializer());
+		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+		redisTemplate.setConnectionFactory(redisConnectionFactory);
+		return redisTemplate;
 	}
+
 
 	/**
 	 * redis娑堟伅鐩戝惉鍣ㄥ鍣� 鍙互娣诲姞澶氫釜鐩戝惉涓嶅悓璇濋鐨剅edis鐩戝惉鍣紝鍙渶瑕佹妸娑堟伅鐩戝惉鍣ㄥ拰鐩稿簲鐨勬秷鎭闃呭鐞嗗櫒缁戝畾锛岃娑堟伅鐩戝惉鍣�
 	 * 閫氳繃鍙嶅皠鎶�鏈皟鐢ㄦ秷鎭闃呭鐞嗗櫒鐨勭浉鍏虫柟娉曡繘琛屼竴浜涗笟鍔″鐞�
 	 * 
 	 * @param connectionFactory
-	 * @param listenerAdapter
 	 * @return
 	 */
 	@Bean
@@ -51,6 +78,12 @@
 
         RedisMessageListenerContainer container = new RedisMessageListenerContainer();
         container.setConnectionFactory(connectionFactory);
+		container.addMessageListener(redisGPSMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_GPS));
+		container.addMessageListener(redisAlarmMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM_RECEIVE));
+		container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH"));
+		container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY));
+		container.addMessageListener(redisPushStreamStatusMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_STATUS_CHANGE));
+		container.addMessageListener(redisPushStreamListMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_LIST_CHANGE));
         return container;
     }
 

--
Gitblit v1.8.0