use of com.alibaba.middleware.race.mom.util.TopicAndFilter in project alibaba-mom by younfor.
the class MessageManager method recieveMsg.
// public static Map<String/* TopicAndFilter+msgOffset */,MessageInfo> messageCacheMap;
/**
* 每个集群有独立的消费进度
* 消息再broker收到后,按照TopicAndFilter 消息分类,每种TopicAndFilter消息有独立的offsetProducer
* 如果要以queueId分多文件,那么再分一层独立的offsetProducer
*/
// private MsgStore mstore = /* new MsgStoreImp();// */new MsgStoreImp_MappedBuffer();
// private FSTConfiguration fst = FSTConfiguration.getDefaultConfiguration();
// private Map<String/* topic@group */,BlockingQueue<String /*id*/>/*reSendMsgQueue*/>topicAndgroup2reSendMsgQueue=new HashMap<>();
// public MessageManager(ConcurrentHashMap<String/* TopicAndFilter+msgOffset */,Message> recoverMsgMap){
// if(recoverMsgMap!=null){
// messageCacheMap=recoverMsgMap;
// }else{
// messageCacheMap=new ConcurrentHashMap<>();
// }
// }
/**
* 打包消息处理
* @param msgSend
* @param producer
*/
public static void recieveMsg(MessageSend msgSend, ChannelHandlerContext producer) {
long start = System.currentTimeMillis();
/*
* 存储处理
*/
msgSend.setProducer(producer.channel());
TopicAndFilter topicAndFilter = new TopicAndFilter(msgSend.getTopic(), msgSend.getProperties());
String[] queueIdAndOffsetArray = ProducerGroup.storeMsg(topicAndFilter, msgSend).split(" ");
int queueIndex = Integer.parseInt(queueIdAndOffsetArray[0]);
int offset = Integer.parseInt(queueIdAndOffsetArray[1]);
logger.debug("currentCanUseOffset " + offset);
/*
* 消息进入待发送队列,等待存储完成()
*/
int i = 0;
for (byte[] body : msgSend.getBodys()) {
Message msg = new Message(msgSend.getTopic(), body, msgSend.getProperties(), msgSend.getBornTime());
msg.setMsgId(msgSend.getSendIds().get(i));
MessageInfo msgInfo = new MessageInfo(msg, producer.channel());
msgInfo.setQueueId(queueIndex);
msgInfo.setOffset(offset++);
msgInfo.setMsgInfoId(topicAndFilter.toString() + queueIndex + "" + String.valueOf(msgInfo.getOffset()));
/*
* 发送处理,加入发送队列,等待存储完成
*/
ConsumerGroup.sendMsg(topicAndFilter, msgInfo);
i++;
}
// logger.error("消息born 到生产者recv处理完毕 cost:"+(System.currentTimeMillis()-msgSend.getBornTime()));
// logger.error("消息recv生产者recv处理完毕 cost:"+(System.currentTimeMillis()-start));
}
use of com.alibaba.middleware.race.mom.util.TopicAndFilter in project alibaba-mom by younfor.
the class Recover method recoverMessage.
public ConcurrentHashMap<String, Message> recoverMessage(List<Offset> makedOffsets) {
long startTime = System.currentTimeMillis();
ConcurrentHashMap<String, Message> msgMap = new ConcurrentHashMap<>(1024 * 128);
System.out.println("offsets:" + makedOffsets);
int recoverNum = 0;
int queueId;
TopicAndFilter topicAndFilter;
for (Offset offset : makedOffsets) {
topicAndFilter = new TopicAndFilter(offset.getTopic(), offset.getFilter());
queueId = offset.getQueueIndex();
// //恢复topicAndgroup2subScribe
// LinkedList<Offset> offsetList;
// if(!topicAndgroup2subScribe.containsKey(topic+"@"+group)){
// offsetList=new LinkedList<Offset>();
// topicAndgroup2subScribe.put(topic+"@"+group, offsetList);
// }else{
// offsetList=topicAndgroup2subScribe.get(topic+"@"+group);
// }
// offsetList.add(Integer.parseInt(queueId),offset);
// //恢复topicAndgroup2sendMsgQueue
// LinkedList<BlockingQueue<String>> sendQueuesList;
// if(!topicAndgroup2sendMsgQueue.containsKey(topic + "@" + group)){
// sendQueuesList=new LinkedList<BlockingQueue<String>>();
// topicAndgroup2sendMsgQueue.put(topic + "@" + group, sendQueuesList);
// }else
// {
// sendQueuesList=topicAndgroup2sendMsgQueue.get(topic + "@" + group);
// }
// BlockingQueue<String>sendQueue=new LinkedBlockingQueue<String>();
// sendQueuesList.add(Integer.parseInt(queueId),sendQueue);
// 消息入内存
int currentOffset = offset.getCurrentoffset();
int MaxOffset = offset.getMaxOffset();
Message msg;
// currentOffset偏移量
int i = 0;
List<byte[]> blist = mstore.readByteNormal(topicAndFilter.toString(), String.valueOf(queueId), currentOffset + 1, MaxOffset);
recoverNum += blist.size();
System.out.println(blist.size());
for (byte[] b : blist) {
try {
msg = (Message) fst.asObject(b);
System.out.println("恢复消息" + msg);
} catch (Exception e) {
continue;
}
msgMap.put(new TopicAndFilter(msg.getTopic(), msg.getProperties()).toString(), msg);
// msgid2offset.put(msg.getMsgId(), currentOffset+i);
i++;
}
}
long endTime = System.currentTimeMillis();
System.out.println("恢复cost:" + (endTime - startTime) + " ,一共恢复" + recoverNum + "条");
return msgMap;
}
Aggregations