diff --git a/pom.xml b/pom.xml index 8487509..d241f1a 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,10 @@ org.springframework.boot spring-boot-starter-tomcat + + org.springframework.boot + spring-boot-starter-logging + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java index 4b5e571..a3a4484 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepliveTimeoutListener.java @@ -1,5 +1,7 @@ package com.genersoft.iot.vmp.gb28181.event.offline; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; @@ -9,23 +11,25 @@ import org.springframework.stereotype.Component; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; -/** +/** * @Description:设备心跳超时监听,借助redis过期特性,进行监听,监听到说明设备心跳超时,发送离线事件 * @author: swwheihei - * @date: 2020年5月6日 上午11:35:46 + * @date: 2020年5月6日 上午11:35:46 */ @Component public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { - @Autowired - private EventPublisher publisher; + @Autowired + private EventPublisher publisher; + private static final Logger log = LoggerFactory.getLogger(KeepliveTimeoutListener.class); - public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { - super(listenerContainer); - } + public KeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer) { + super(listenerContainer); + } - /** + /** * 监听失效的key,key格式为keeplive_deviceId + * * @param message * @param pattern */ @@ -33,12 +37,14 @@ public class KeepliveTimeoutListener extends KeyExpirationEventMessageListener { public void onMessage(Message message, byte[] pattern) { // 获取失效的key String expiredKey = message.toString(); - if(!expiredKey.startsWith(VideoManagerConstants.KEEPLIVEKEY_PREFIX)){ - System.out.println("收到redis过期监听,但开头不是"+VideoManagerConstants.KEEPLIVEKEY_PREFIX+",忽略"); - return; + if (!expiredKey.startsWith(VideoManagerConstants.KEEPLIVEKEY_PREFIX)) { + if (log.isDebugEnabled()) { + log.debug("收到redis过期监听,但开头不是" + VideoManagerConstants.KEEPLIVEKEY_PREFIX + ",忽略"); + } + return; } - - String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(),expiredKey.length()); + + String deviceId = expiredKey.substring(VideoManagerConstants.KEEPLIVEKEY_PREFIX.length(), expiredKey.length()); publisher.outlineEventPublish(deviceId, VideoManagerConstants.EVENT_OUTLINE_TIMEOUT); } }