Search in sources :

Example 1 with PushConsumer

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

the class SimplePushConsumer method main.

public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    final PushConsumer consumer = messagingAccessPoint.createPushConsumer(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.attachQueue("OMS_HELLO_TOPIC", new MessageListener() {

        @Override
        public void onMessage(final Message message, final ReceivedMessageContext context) {
            System.out.printf("Received one message: %s%n", message.headers().getString(MessageHeader.MESSAGE_ID));
            context.ack();
        }
    });
    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
Also used : Message(io.openmessaging.Message) PushConsumer(io.openmessaging.PushConsumer) MessageListener(io.openmessaging.MessageListener) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) ReceivedMessageContext(io.openmessaging.ReceivedMessageContext)

Example 2 with PushConsumer

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

the class SimplePushConsumer method main.

public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    final PushConsumer consumer = messagingAccessPoint.createPushConsumer(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.attachQueue("OMS_HELLO_TOPIC", new MessageListener() {

        @Override
        public void onMessage(final Message message, final ReceivedMessageContext context) {
            System.out.printf("Received one message: %s%n", message.headers().getString(MessageHeader.MESSAGE_ID));
            context.ack();
        }
    });
    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
Also used : Message(io.openmessaging.Message) PushConsumer(io.openmessaging.PushConsumer) MessageListener(io.openmessaging.MessageListener) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) ReceivedMessageContext(io.openmessaging.ReceivedMessageContext)

Aggregations

Message (io.openmessaging.Message)2 MessageListener (io.openmessaging.MessageListener)2 MessagingAccessPoint (io.openmessaging.MessagingAccessPoint)2 PushConsumer (io.openmessaging.PushConsumer)2 ReceivedMessageContext (io.openmessaging.ReceivedMessageContext)2