|  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.RedisKeyExpirationEventMessageListener; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetup; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetting; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | import org.springframework.data.redis.listener.RedisMessageListenerContainer; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private ZLMRESTfulUtils zlmresTfulUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetup userSetup; | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IMediaServerService mediaServerService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer, UserSetup userSetup) { | 
|---|
|  |  |  | super(listenerContainer, userSetup); | 
|---|
|  |  |  | public ZLMKeepliveTimeoutListener(RedisMessageListenerContainer listenerContainer, UserSetting userSetting) { | 
|---|
|  |  |  | super(listenerContainer, userSetting); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public void onMessage(Message message, byte[] pattern) { | 
|---|
|  |  |  | //  获取失效的key | 
|---|
|  |  |  | String expiredKey = message.toString(); | 
|---|
|  |  |  | String KEEPLIVEKEY_PREFIX = VideoManagerConstants.MEDIA_SERVER_KEEPALIVE_PREFIX + userSetup.getServerId() + "_"; | 
|---|
|  |  |  | String KEEPLIVEKEY_PREFIX = VideoManagerConstants.MEDIA_SERVER_KEEPALIVE_PREFIX + userSetting.getServerId() + "_"; | 
|---|
|  |  |  | if(!expiredKey.startsWith(KEEPLIVEKEY_PREFIX)){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (mediaServerConfig == null) { | 
|---|
|  |  |  | publisher.zlmOfflineEventPublish(mediaServerId); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | logger.info("[zlm心跳到期]:{}验证后zlm仍在线,回复心跳信息", mediaServerId); | 
|---|
|  |  |  | logger.info("[zlm心跳到期]:{}验证后zlm仍在线,恢复心跳信息", mediaServerId); | 
|---|
|  |  |  | // 添加zlm信息 | 
|---|
|  |  |  | mediaServerService.updateMediaServerKeepalive(mediaServerId, mediaServerConfig); | 
|---|
|  |  |  | } | 
|---|