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.
35 lines
1.3 KiB
35 lines
1.3 KiB
package com.bx.imserver.task;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.bx.imcommon.contant.IMRedisKey;
|
|
import com.bx.imcommon.enums.IMCmdType;
|
|
import com.bx.imcommon.model.IMRecvInfo;
|
|
import com.bx.imserver.netty.IMServerGroup;
|
|
import com.bx.imserver.netty.processor.AbstractMessageProcessor;
|
|
import com.bx.imserver.netty.processor.ProcessorFactory;
|
|
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;
|
|
|
|
@Slf4j
|
|
@Component
|
|
public class PullGroupMessageTask extends AbstractPullMessageTask {
|
|
|
|
@Autowired
|
|
private RedisTemplate<String,Object> redisTemplate;
|
|
|
|
@Override
|
|
public void pullMessage() {
|
|
// 从redis拉取未读消息
|
|
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);
|
|
AbstractMessageProcessor processor = ProcessorFactory.createProcessor(IMCmdType.GROUP_MESSAGE);
|
|
processor.process(recvInfo);
|
|
}
|
|
}
|
|
|
|
}
|
|
|