소스 검색

补充心跳日志

xsx 1 년 전
부모
커밋
8707b24e2f

+ 1 - 1
im-server/src/main/java/com/bx/imserver/netty/IMChannelHandler.java

@@ -74,7 +74,7 @@ public class IMChannelHandler extends SimpleChannelInboundHandler<IMSendInfo> {
             RedisTemplate<String, Object> redisTemplate = SpringContextHolder.getBean("redisTemplate");
             String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
             redisTemplate.delete(key);
-            log.info("断开连接,userId:{},终端类型:{}", userId, terminal);
+            log.info("断开连接,userId:{},终端类型:{},{}", userId, terminal, ctx.channel().id().asLongText());
         }
     }
 

+ 4 - 1
im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java

@@ -30,7 +30,7 @@ public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo
         IMSendInfo sendInfo = new IMSendInfo();
         sendInfo.setCmd(IMCmdType.HEART_BEAT.code());
         ctx.channel().writeAndFlush(sendInfo);
-
+        ;
         // 设置属性
         AttributeKey<Long> heartBeatAttr = AttributeKey.valueOf(ChannelAttrKey.HEARTBEAT_TIMES);
         Long heartbeatTimes = ctx.channel().attr(heartBeatAttr).get();
@@ -44,6 +44,9 @@ public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo
             String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
             redisTemplate.expire(key, IMConstant.ONLINE_TIMEOUT_SECOND, TimeUnit.SECONDS);
         }
+        AttributeKey<Long> userIdAttr = AttributeKey.valueOf(ChannelAttrKey.USER_ID);
+        Long userId = ctx.channel().attr(userIdAttr).get();
+        log.info("心跳,userId:{},{}",userId,ctx.channel().id().asLongText());
     }
 
     @Override