Browse Source

补充心跳日志

master
xsx 2 years ago
parent
commit
8707b24e2f
  1. 2
      im-server/src/main/java/com/bx/imserver/netty/IMChannelHandler.java
  2. 5
      im-server/src/main/java/com/bx/imserver/netty/processor/HeartbeatProcessor.java

2
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"); RedisTemplate<String, Object> redisTemplate = SpringContextHolder.getBean("redisTemplate");
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString()); String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
redisTemplate.delete(key); redisTemplate.delete(key);
log.info("断开连接,userId:{},终端类型:{}", userId, terminal); log.info("断开连接,userId:{},终端类型:{},{}", userId, terminal, ctx.channel().id().asLongText());
} }
} }

5
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(); IMSendInfo sendInfo = new IMSendInfo();
sendInfo.setCmd(IMCmdType.HEART_BEAT.code()); sendInfo.setCmd(IMCmdType.HEART_BEAT.code());
ctx.channel().writeAndFlush(sendInfo); ctx.channel().writeAndFlush(sendInfo);
;
// 设置属性 // 设置属性
AttributeKey<Long> heartBeatAttr = AttributeKey.valueOf(ChannelAttrKey.HEARTBEAT_TIMES); AttributeKey<Long> heartBeatAttr = AttributeKey.valueOf(ChannelAttrKey.HEARTBEAT_TIMES);
Long heartbeatTimes = ctx.channel().attr(heartBeatAttr).get(); 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()); String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
redisTemplate.expire(key, IMConstant.ONLINE_TIMEOUT_SECOND, TimeUnit.SECONDS); 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 @Override

Loading…
Cancel
Save