use of cn.tellwhy.third.rocket.PullConsumer 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());
}
}
Aggregations