Consumer Example

    1.2 PushConsumer

    1. public static void test(String[] args) throws Throwable {
    2. final String masterHostAndPort = "localhost:8000";
    3. final String topic = "test";
    4. final String group = "test-group";
    5. final ConsumerConfig consumerConfig = new ConsumerConfig(masterHostAndPort, group);
    6. final MessageSessionFactory messageSessionFactory = new TubeSingleSessionFactory(consumerConfig);
    7. final PushMessageConsumer pushConsumer = messageSessionFactory.createPushConsumer(consumerConfig);
    8. @Override
    9. public void receiveMessages(PeerInfo peerInfo, List<Message> messages) throws InterruptedException {
    10. for (Message message : messages) {
    11. System.out.println("received message : " + new String(message.getData()));
    12. }
    13. }
    14. @Override
    15. return null;
    16. @Override
    17. public void stop() {
    18. //
    19. }
    20. });
    21. pushConsumer.completeSubscribe();
    22. CountDownLatch latch = new CountDownLatch(1);
    23. latch.await(10, TimeUnit.MINUTES);