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.

38 lines
1.3 KiB

package com.bx.imserver.task;
3 years ago
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;
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(":", IMRedisKey.IM_MESSAGE_PRIVATE_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.PRIVATE_MESSAGE);
3 years ago
processor.process(recvInfo);
3 years ago
}
}
3 years ago
}