You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

package com.bx.imserver.task;
import com.alibaba.fastjson.JSONObject;
import com.bx.imcommon.contant.IMRedisKey;
3 years ago
import com.bx.imcommon.enums.IMCmdType;
3 years ago
import com.bx.imcommon.model.IMRecvInfo;
3 years ago
import com.bx.imserver.netty.IMServerGroup;
3 years ago
import com.bx.imserver.netty.processor.AbstractMessageProcessor;
import com.bx.imserver.netty.processor.ProcessorFactory;
2 years ago
import lombok.RequiredArgsConstructor;
3 years ago
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
3 years ago
@Slf4j
@Component
2 years ago
@RequiredArgsConstructor
public class PullGroupMessageTask extends AbstractPullMessageTask {
3 years ago
2 years ago
private final RedisTemplate<String, Object> redisTemplate;
3 years ago
@Override
public void pullMessage() {
3 years ago
// 从redis拉取未读消息
2 years ago
String key = String.join(":", IMRedisKey.IM_MESSAGE_GROUP_QUEUE, IMServerGroup.serverId + "");
JSONObject jsonObject = (JSONObject) redisTemplate.opsForList().leftPop(key, 10, TimeUnit.SECONDS);
if (jsonObject != null) {
IMRecvInfo recvInfo = jsonObject.toJavaObject(IMRecvInfo.class);
3 years ago
AbstractMessageProcessor processor = ProcessorFactory.createProcessor(IMCmdType.GROUP_MESSAGE);
3 years ago
processor.process(recvInfo);
3 years ago
}
}
3 years ago
}