use of cn.tellwhy.third.rocket.PushConsumer in project warn-report by saaavsaaa.
the class TestProcess method TestReceive.
@Test
public void TestReceive() throws InterruptedException, RemotingException, MQBrokerException, MQClientException {
// "192.168.1.45:9876";
final String address = "192.168.1.45:9876";
final String topic = "testTopic2";
MessageListenerConcurrently listener = new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
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);
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
};
final String consumerGroup = "cgr1";
final String subExpression = "*";
PushConsumer consumer = null;
try {
consumer = new PushConsumer(address, consumerGroup, topic, subExpression, listener);
} catch (MQClientException e) {
consumer = new PushConsumer("192.168.1.45:9876", consumerGroup, topic, subExpression, listener);
}
if (consumer != null) {
Thread.sleep(1000);
}
}
Aggregations