去除jedis,方便支持redis集群
parent
eb177a6742
commit
82ab6b1760
12
pom.xml
12
pom.xml
|
@ -61,13 +61,6 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<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>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -94,11 +87,6 @@
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>redis.clients</groupId>
|
|
||||||
<artifactId>jedis</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- druid数据库连接池 -->
|
<!-- druid数据库连接池 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.genersoft.iot.vmp.conf;
|
package com.genersoft.iot.vmp.conf;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.parser.ParserConfig;
|
||||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||||
import com.genersoft.iot.vmp.service.impl.*;
|
import com.genersoft.iot.vmp.service.impl.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
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.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
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.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.listener.PatternTopic;
|
import org.springframework.data.redis.listener.PatternTopic;
|
||||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
import com.alibaba.fastjson.parser.ParserConfig;
|
|
||||||
import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer;
|
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配置
|
* @description:Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置
|
||||||
|
@ -28,23 +28,6 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class RedisConfig extends CachingConfigurerSupport {
|
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
|
@Autowired
|
||||||
private RedisGpsMsgListener redisGPSMsgListener;
|
private RedisGpsMsgListener redisGPSMsgListener;
|
||||||
|
|
||||||
|
@ -61,36 +44,24 @@ public class RedisConfig extends CachingConfigurerSupport {
|
||||||
private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener;
|
private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener;
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public JedisPool jedisPool() {
|
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||||
if (StringUtils.isBlank(password)) {
|
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
||||||
password = null;
|
// 使用fastJson序列化
|
||||||
}
|
FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
|
||||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
// value值的序列化采用fastJsonRedisSerializer
|
||||||
poolConfig.setMaxIdle(poolMaxIdle);
|
redisTemplate.setValueSerializer(fastJsonRedisSerializer);
|
||||||
poolConfig.setMaxTotal(poolMaxTotal);
|
redisTemplate.setHashValueSerializer(fastJsonRedisSerializer);
|
||||||
// 秒转毫秒
|
// 全局开启AutoType,不建议使用
|
||||||
poolConfig.setMaxWaitMillis(poolMaxWait * 1000L);
|
ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
|
||||||
JedisPool jp = new JedisPool(poolConfig, host, port, timeout * 1000, password, database);
|
// 建议使用这种方式,小范围指定白名单,需要序列化的类
|
||||||
return jp;
|
// ParserConfig.getGlobalInstance().addAccept("com.avatar");
|
||||||
|
// key的序列化采用StringRedisSerializer
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
return redisTemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
// 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监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
|
* redis消息监听器容器 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMe
|
||||||
RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection();
|
RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection();
|
||||||
Properties config = connection.getConfig("notify-keyspace-events");
|
Properties config = connection.getConfig("notify-keyspace-events");
|
||||||
try {
|
try {
|
||||||
if (!config.getProperty("notify-keyspace-events").equals(keyspaceNotificationsConfigParameter)) {
|
if (!keyspaceNotificationsConfigParameter.equals(config.getProperty("notify-keyspace-events"))) {
|
||||||
connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
|
connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -445,12 +445,15 @@ public class ZLMHttpHookListener {
|
||||||
if (streamInfo!=null){
|
if (streamInfo!=null){
|
||||||
redisCatchStorage.stopPlay(streamInfo);
|
redisCatchStorage.stopPlay(streamInfo);
|
||||||
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||||
|
// 如果正在给上级推送,则发送bye
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
|
streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
|
||||||
if (streamInfo != null) {
|
if (streamInfo != null) {
|
||||||
redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
|
redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
|
||||||
streamInfo.getStream(), null);
|
streamInfo.getStream(), null);
|
||||||
}
|
}
|
||||||
|
// 如果正在给上级推送,则发送bye
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
if (!"rtp".equals(app)){
|
if (!"rtp".equals(app)){
|
||||||
|
|
|
@ -36,7 +36,6 @@ import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||||
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
|
||||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
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.utils.redis.RedisUtil;
|
||||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||||
|
|
||||||
|
@ -91,9 +90,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private EventPublisher publisher;
|
private EventPublisher publisher;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
JedisUtil jedisUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化
|
* 初始化
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -148,6 +148,8 @@ public class PlayController {
|
||||||
// 超时处理
|
// 超时处理
|
||||||
result.onTimeout(()->{
|
result.onTimeout(()->{
|
||||||
logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId));
|
logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId));
|
||||||
|
redisCatchStorage.stopPlay(streamInfo);
|
||||||
|
storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
|
||||||
RequestMessage msg = new RequestMessage();
|
RequestMessage msg = new RequestMessage();
|
||||||
msg.setId(uuid);
|
msg.setId(uuid);
|
||||||
msg.setKey(key);
|
msg.setKey(key);
|
||||||
|
|
Loading…
Reference in New Issue