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.

36 lines
1.2 KiB

package com.bx.imserver.task;
3 years ago
3 years ago
import com.bx.imcommon.contant.RedisKey;
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;
3 years ago
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
3 years ago
@Slf4j
@Component
public class PullUnreadPrivateMessageTask extends AbstractPullMessageTask {
3 years ago
@Autowired
private RedisTemplate<String,Object> redisTemplate;
@Override
public void pullMessage() {
3 years ago
// 从redis拉取未读消息
String key = String.join(":",RedisKey.IM_UNREAD_PRIVATE_QUEUE ,IMServerGroup.serverId+"");
IMRecvInfo recvInfo = (IMRecvInfo)redisTemplate.opsForList().leftPop(key,10, TimeUnit.SECONDS);
if(recvInfo != null) {
3 years ago
AbstractMessageProcessor processor = ProcessorFactory.createProcessor(IMCmdType.PRIVATE_MESSAGE);
3 years ago
processor.process(recvInfo);
3 years ago
}
}
3 years ago
}