Consumer Example
1.2 PushConsumer
public static void test(String[] args) throws Throwable {
final String masterHostAndPort = "localhost:8000";
final String topic = "test";
final String group = "test-group";
final ConsumerConfig consumerConfig = new ConsumerConfig(masterHostAndPort, group);
final MessageSessionFactory messageSessionFactory = new TubeSingleSessionFactory(consumerConfig);
final PushMessageConsumer pushConsumer = messageSessionFactory.createPushConsumer(consumerConfig);
@Override
public void receiveMessages(PeerInfo peerInfo, List<Message> messages) throws InterruptedException {
for (Message message : messages) {
System.out.println("received message : " + new String(message.getData()));
}
}
@Override
return null;
@Override
public void stop() {
//
}
});
pushConsumer.completeSubscribe();
CountDownLatch latch = new CountDownLatch(1);
latch.await(10, TimeUnit.MINUTES);