Search in sources :

Example 1 with PullConsumer

use of io.openmessaging.PullConsumer in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class SimplePullConsumer method main.

public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    final PullConsumer consumer = messagingAccessPoint.createPullConsumer("OMS_HELLO_TOPIC", OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "OMS_CONSUMER"));
    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            consumer.shutdown();
            messagingAccessPoint.shutdown();
        }
    }));
    consumer.startup();
    System.out.printf("Consumer startup OK%n");
    while (true) {
        Message message = consumer.poll();
        if (message != null) {
            String msgId = message.headers().getString(MessageHeader.MESSAGE_ID);
            System.out.printf("Received one message: %s%n", msgId);
            consumer.ack(msgId);
        }
    }
}
Also used : Message(io.openmessaging.Message) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) PullConsumer(io.openmessaging.PullConsumer)

Example 2 with PullConsumer

use of io.openmessaging.PullConsumer in project rocketmq by apache.

the class SimplePullConsumer method main.

public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    final PullConsumer consumer = messagingAccessPoint.createPullConsumer("OMS_HELLO_TOPIC", OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "OMS_CONSUMER"));
    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            consumer.shutdown();
            messagingAccessPoint.shutdown();
        }
    }));
    consumer.startup();
    System.out.printf("Consumer startup OK%n");
    while (true) {
        Message message = consumer.poll();
        if (message != null) {
            String msgId = message.headers().getString(MessageHeader.MESSAGE_ID);
            System.out.printf("Received one message: %s%n", msgId);
            consumer.ack(msgId);
        }
    }
}
Also used : Message(io.openmessaging.Message) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) PullConsumer(io.openmessaging.PullConsumer)

Aggregations

Message (io.openmessaging.Message)2 MessagingAccessPoint (io.openmessaging.MessagingAccessPoint)2 PullConsumer (io.openmessaging.PullConsumer)2