use of com.alibaba.rocketmq.common.message.MessageQueue in project warn-report by saaavsaaa.
the class TestProcess method TestPull.
@Test
public void TestPull() throws MQClientException {
// "192.168.1.44:9876";
final String address = "192.168.1.45:9876";
final String topic = "topicTest";
final String consumerGroup = "cgr";
final String subExpression = "*";
PullConsumer consumer = new PullConsumer(address, consumerGroup);
Set<MessageQueue> mqs = consumer.getMessageQueue(topic);
for (MessageQueue mq : mqs) {
System.out.println("Consume from the queue: " + mq);
SINGLE_MQ: while (true) {
try {
PullResult pullResult = consumer.pullBlockIfNotFound(mq, subExpression, getMessageQueueOffset(mq), 32);
System.out.println(pullResult);
putMessageQueueOffset(mq, pullResult.getNextBeginOffset());
switch(pullResult.getPullStatus()) {
case FOUND:
List<MessageExt> msgs = pullResult.getMsgFoundList();
for (MessageExt ext : msgs) {
String key = ext.getKeys();
String keys = ext.getProperty("KEYS");
String value = new String(ext.getBody());
System.out.println("key : " + key + "; KEYS :" + keys + "; body : " + value + "\n");
}
break;
case NO_MATCHED_MSG:
break;
case NO_NEW_MSG:
break SINGLE_MQ;
case OFFSET_ILLEGAL:
break;
default:
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
for (Map.Entry<MessageQueue, Long> one : offseTable.entrySet()) {
System.out.println(one.getValue());
}
}
use of com.alibaba.rocketmq.common.message.MessageQueue in project warn-report by saaavsaaa.
the class PullConsumerCluter method getMessage.
public List<MessageExt> getMessage(final String topic, final Long offset, final String subExpression) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
List<MessageExt> result = new ArrayList<MessageExt>();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
for (MessageQueue mq : mqs) {
PullResult pullResult = consumer.pullBlockIfNotFound(mq, subExpression, offset, 1);
if (pullResult.getPullStatus() == PullStatus.FOUND) {
List<MessageExt> extList = pullResult.getMsgFoundList();
result.addAll(extList);
}
}
return result;
}
use of com.alibaba.rocketmq.common.message.MessageQueue in project jstorm by alibaba.
the class MetaSimpleClient method rebalanceMqList.
/**
* rebalanceMqList must run after commit
*
* @throws MQClientException
*/
public void rebalanceMqList() throws Exception {
LOG.info("Begin to do rebalance operation");
Set<MessageQueue> newMqs = getMQ();
Set<MessageQueue> oldMqs = currentOffsets.keySet();
if (oldMqs.equals(newMqs) == true) {
LOG.info("No change of meta queues " + newMqs);
return;
}
Set<MessageQueue> removeMqs = new HashSet<MessageQueue>();
removeMqs.addAll(oldMqs);
removeMqs.removeAll(newMqs);
Set<MessageQueue> addMqs = new HashSet<MessageQueue>();
addMqs.addAll(newMqs);
addMqs.removeAll(oldMqs);
LOG.info("Remove " + removeMqs);
for (MessageQueue mq : removeMqs) {
Long offset = frontOffsets.remove(mq);
updateOffsetToZk(mq, offset);
backendOffset.remove(mq);
}
LOG.info("Add " + addMqs);
for (MessageQueue mq : addMqs) {
long offset = getOffsetFromZk(mq);
frontOffsets.put(mq, offset);
backendOffset.put(mq, offset);
}
}
use of com.alibaba.rocketmq.common.message.MessageQueue in project jstorm by alibaba.
the class MetaSimpleClient method initOffset.
protected Map<MessageQueue, Long> initOffset() throws MQClientException {
Set<MessageQueue> queues = getMQ();
Map<MessageQueue, Long> ret = new HashMap<MessageQueue, Long>();
Set<MessageQueue> noOffsetQueues = new HashSet<MessageQueue>();
if (metaSpoutConfig.getStartTimeStamp() != null) {
Long timeStamp = metaSpoutConfig.getStartTimeStamp();
for (MessageQueue mq : queues) {
long offset = consumer.searchOffset(mq, timeStamp);
if (offset >= 0) {
LOG.info("Successfully get " + mq + " offset of timestamp " + new Date(timeStamp));
ret.put(mq, offset);
} else {
LOG.info("Failed to get " + mq + " offset of timestamp " + new Date(timeStamp));
noOffsetQueues.add(mq);
}
}
} else {
noOffsetQueues.addAll(queues);
}
if (noOffsetQueues.size() == 0) {
return ret;
}
for (MessageQueue mq : noOffsetQueues) {
long offset = getOffsetFromZk(mq);
ret.put(mq, offset);
}
return ret;
}
Aggregations