Commit 7e428f823128ec5fdbff3a8f73e9ea1f1a4a23ba
1 parent
fab21b36
修复redis配置功能在redis配置了 notify-keyspace-events时无法强制配置的问题
Showing
4 changed files
with
60 additions
and
28 deletions
src/main/java/com/genersoft/iot/vmp/conf/RedisKeyExpirationEventMessageListener.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.conf; | |
| 2 | + | |
| 3 | +import org.springframework.data.redis.connection.RedisConnection; | |
| 4 | +import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; | |
| 5 | +import org.springframework.data.redis.listener.RedisMessageListenerContainer; | |
| 6 | +import org.springframework.util.StringUtils; | |
| 7 | + | |
| 8 | +import java.util.Properties; | |
| 9 | + | |
| 10 | +public class RedisKeyExpirationEventMessageListener extends KeyExpirationEventMessageListener { | |
| 11 | + | |
| 12 | + private UserSetup userSetup; | |
| 13 | + private RedisMessageListenerContainer listenerContainer; | |
| 14 | + private String keyspaceNotificationsConfigParameter = "EA"; | |
| 15 | + | |
| 16 | + public RedisKeyExpirationEventMessageListener(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { | |
| 17 | + super(listenerContainer); | |
| 18 | + this.listenerContainer = listenerContainer; | |
| 19 | + this.userSetup = userSetup; | |
| 20 | + } | |
| 21 | + | |
| 22 | + @Override | |
| 23 | + public void init() { | |
| 24 | + if (!userSetup.getRedisConfig()) { | |
| 25 | + // 配置springboot默认Config为空,即不让应用去修改redis的默认配置,因为Redis服务出于安全会禁用CONFIG命令给远程用户使用 | |
| 26 | + setKeyspaceNotificationsConfigParameter(""); | |
| 27 | + }else { | |
| 28 | + | |
| 29 | + RedisConnection connection = this.listenerContainer.getConnectionFactory().getConnection(); | |
| 30 | + Properties config = connection.getConfig("notify-keyspace-events"); | |
| 31 | + try { | |
| 32 | + if (!config.getProperty("notify-keyspace-events").equals(keyspaceNotificationsConfigParameter)) { | |
| 33 | + connection.setConfig("notify-keyspace-events", keyspaceNotificationsConfigParameter); | |
| 34 | + } | |
| 35 | + } finally { | |
| 36 | + connection.close(); | |
| 37 | + } | |
| 38 | + } | |
| 39 | + super.init(); | |
| 40 | + } | |
| 41 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.offline; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; | |
| 3 | 4 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 4 | 5 | import org.slf4j.Logger; |
| 5 | 6 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -7,12 +8,16 @@ import org.springframework.beans.factory.InitializingBean; |
| 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | 9 | import org.springframework.context.annotation.DependsOn; |
| 9 | 10 | import org.springframework.data.redis.connection.Message; |
| 11 | +import org.springframework.data.redis.connection.RedisConnection; | |
| 10 | 12 | import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; |
| 11 | 13 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; |
| 12 | 14 | import org.springframework.stereotype.Component; |
| 13 | 15 | |
| 14 | 16 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 15 | 17 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 18 | +import org.springframework.util.StringUtils; | |
| 19 | + | |
| 20 | +import java.util.Properties; | |
| 16 | 21 | |
| 17 | 22 | /** |
| 18 | 23 | * @description:设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件 |
| ... | ... | @@ -20,7 +25,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 20 | 25 | * @date: 2020年5月6日 上午11:35:46 |
| 21 | 26 | */ |
| 22 | 27 | @Component |
| 23 | -public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessageListener { | |
| 28 | +public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEventMessageListener { | |
| 24 | 29 | |
| 25 | 30 | private Logger logger = LoggerFactory.getLogger(KeepaliveTimeoutListenerForPlatform.class); |
| 26 | 31 | |
| ... | ... | @@ -30,17 +35,8 @@ public class KeepaliveTimeoutListenerForPlatform extends KeyExpirationEventMessa |
| 30 | 35 | @Autowired |
| 31 | 36 | private UserSetup userSetup; |
| 32 | 37 | |
| 33 | - @Override | |
| 34 | - public void init() { | |
| 35 | - if (!userSetup.getRedisConfig()) { | |
| 36 | - // 配置springboot默认Config为空,即不让应用去修改redis的默认配置,因为Redis服务出于安全会禁用CONFIG命令给远程用户使用 | |
| 37 | - setKeyspaceNotificationsConfigParameter(""); | |
| 38 | - } | |
| 39 | - super.init(); | |
| 40 | - } | |
| 41 | - | |
| 42 | - public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer) { | |
| 43 | - super(listenerContainer); | |
| 38 | + public KeepaliveTimeoutListenerForPlatform(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { | |
| 39 | + super(listenerContainer, userSetup); | |
| 44 | 40 | } |
| 45 | 41 | |
| 46 | 42 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java
| 1 | 1 | package com.genersoft.iot.vmp.gb28181.event.offline; |
| 2 | 2 | |
| 3 | +import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; | |
| 3 | 4 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 4 | 5 | import org.slf4j.Logger; |
| 5 | 6 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -20,7 +21,7 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 20 | 21 | * @date: 2020年5月6日 上午11:35:46 |
| 21 | 22 | */ |
| 22 | 23 | @Component |
| 23 | -public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { | |
| 24 | +public class KeepliveTimeoutListener extends RedisKeyExpirationEventMessageListener { | |
| 24 | 25 | |
| 25 | 26 | private Logger logger = LoggerFactory.getLogger(KeepliveTimeoutListener.class); |
| 26 | 27 | |
| ... | ... | @@ -30,6 +31,10 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { |
| 30 | 31 | @Autowired |
| 31 | 32 | private UserSetup userSetup; |
| 32 | 33 | |
| 34 | + public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { | |
| 35 | + super(listenerContainer, userSetup); | |
| 36 | + } | |
| 37 | + | |
| 33 | 38 | @Override |
| 34 | 39 | public void init() { |
| 35 | 40 | if (!userSetup.getRedisConfig()) { |
| ... | ... | @@ -39,9 +44,6 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { |
| 39 | 44 | super.init(); |
| 40 | 45 | } |
| 41 | 46 | |
| 42 | - public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { | |
| 43 | - super(listenerContainer); | |
| 44 | - } | |
| 45 | 47 | |
| 46 | 48 | /** |
| 47 | 49 | * 监听失效的key,key格式为keeplive_deviceId | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/event/ZLMKeepliveTimeoutListener.java
| ... | ... | @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.media.zlm.event; |
| 2 | 2 | |
| 3 | 3 | import com.alibaba.fastjson.JSONObject; |
| 4 | 4 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 5 | +import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; | |
| 5 | 6 | import com.genersoft.iot.vmp.conf.UserSetup; |
| 6 | 7 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 7 | 8 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| ... | ... | @@ -21,7 +22,7 @@ import org.springframework.stereotype.Component; |
| 21 | 22 | * @date: 2020年5月6日 上午11:35:46 |
| 22 | 23 | */ |
| 23 | 24 | @Component |
| 24 | -public class ZLMKeepliveTimeoutListener extends KeyExpirationEventMessageListener { | |
| 25 | +public class ZLMKeepliveTimeoutListener extends RedisKeyExpirationEventMessageListener { | |
| 25 | 26 | |
| 26 | 27 | private Logger logger = LoggerFactory.getLogger(ZLMKeepliveTimeoutListener.class); |
| 27 | 28 | |
| ... | ... | @@ -37,20 +38,12 @@ public class ZLMKeepliveTimeoutListener extends KeyExpirationEventMessageListene |
| 37 | 38 | @Autowired |
| 38 | 39 | private IMediaServerService mediaServerService; |
| 39 | 40 | |
| 40 | - @Override | |
| 41 | - public void init() { | |
| 42 | - if (!userSetup.getRedisConfig()) { | |
| 43 | - // 配置springboot默认Config为空,即不让应用去修改redis的默认配置,因为Redis服务出于安全会禁用CONFIG命令给远程用户使用 | |
| 44 | - setKeyspaceNotificationsConfigParameter(""); | |
| 45 | - } | |
| 46 | - super.init(); | |
| 41 | + public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { | |
| 42 | + super(listenerContainer, userSetup); | |
| 47 | 43 | } |
| 48 | 44 | |
| 49 | - public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { | |
| 50 | - super(listenerContainer); | |
| 51 | - } | |
| 52 | 45 | |
| 53 | - /** | |
| 46 | + /** | |
| 54 | 47 | * 监听失效的key,key格式为keeplive_deviceId |
| 55 | 48 | * @param message |
| 56 | 49 | * @param pattern | ... | ... |