|
|
@ -6,12 +6,12 @@ import com.bx.imcommon.contant.IMRedisKey; |
|
|
import com.bx.imcommon.enums.IMCmdType; |
|
|
import com.bx.imcommon.enums.IMCmdType; |
|
|
import com.bx.imcommon.model.IMHeartbeatInfo; |
|
|
import com.bx.imcommon.model.IMHeartbeatInfo; |
|
|
import com.bx.imcommon.model.IMSendInfo; |
|
|
import com.bx.imcommon.model.IMSendInfo; |
|
|
|
|
|
import com.bx.imcommon.mq.RedisMQTemplate; |
|
|
import com.bx.imserver.constant.ChannelAttrKey; |
|
|
import com.bx.imserver.constant.ChannelAttrKey; |
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
import io.netty.channel.ChannelHandlerContext; |
|
|
import io.netty.util.AttributeKey; |
|
|
import io.netty.util.AttributeKey; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
|
|
import org.springframework.stereotype.Component; |
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
@ -22,12 +22,12 @@ import java.util.concurrent.TimeUnit; |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo> { |
|
|
public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo> { |
|
|
|
|
|
|
|
|
private final RedisTemplate<String, Object> redisTemplate; |
|
|
private final RedisMQTemplate redisMQTemplate; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void process(ChannelHandlerContext ctx, IMHeartbeatInfo beatInfo) { |
|
|
public void process(ChannelHandlerContext ctx, IMHeartbeatInfo beatInfo) { |
|
|
// 响应ws
|
|
|
// 响应ws
|
|
|
IMSendInfo sendInfo = new IMSendInfo(); |
|
|
IMSendInfo<Object> sendInfo = new IMSendInfo<>(); |
|
|
sendInfo.setCmd(IMCmdType.HEART_BEAT.code()); |
|
|
sendInfo.setCmd(IMCmdType.HEART_BEAT.code()); |
|
|
ctx.channel().writeAndFlush(sendInfo); |
|
|
ctx.channel().writeAndFlush(sendInfo); |
|
|
// 设置属性
|
|
|
// 设置属性
|
|
|
@ -41,7 +41,7 @@ public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo |
|
|
AttributeKey<Integer> terminalAttr = AttributeKey.valueOf(ChannelAttrKey.TERMINAL_TYPE); |
|
|
AttributeKey<Integer> terminalAttr = AttributeKey.valueOf(ChannelAttrKey.TERMINAL_TYPE); |
|
|
Integer terminal = ctx.channel().attr(terminalAttr).get(); |
|
|
Integer terminal = ctx.channel().attr(terminalAttr).get(); |
|
|
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); |
|
|
redisMQTemplate.expire(key, IMConstant.ONLINE_TIMEOUT_SECOND, TimeUnit.SECONDS); |
|
|
} |
|
|
} |
|
|
AttributeKey<Long> userIdAttr = AttributeKey.valueOf(ChannelAttrKey.USER_ID); |
|
|
AttributeKey<Long> userIdAttr = AttributeKey.valueOf(ChannelAttrKey.USER_ID); |
|
|
Long userId = ctx.channel().attr(userIdAttr).get(); |
|
|
Long userId = ctx.channel().attr(userIdAttr).get(); |
|
|
|