Search in sources :

Example 1 with MessagingAccessPoint

use of io.openmessaging.MessagingAccessPoint 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 MessagingAccessPoint

use of io.openmessaging.MessagingAccessPoint 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 3 with MessagingAccessPoint

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

the class PullConsumerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPullConsumer(queueName, OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));
    Field field = PullConsumerImpl.class.getDeclaredField("rocketmqPullConsumer");
    field.setAccessible(true);
    // Replace
    field.set(consumer, rocketmqPullConsumer);
    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);
    messagingAccessPoint.startup();
    consumer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) Before(org.junit.Before)

Example 4 with MessagingAccessPoint

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

the class ProducerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createProducer();
    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);
    messagingAccessPoint.startup();
    producer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) Before(org.junit.Before)

Example 5 with MessagingAccessPoint

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

the class PushConsumerImplTest method init.

@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory.getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(OMS.newKeyValue().put(NonStandardKeys.CONSUMER_GROUP, "TestGroup"));
    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    // Replace
    field.set(consumer, rocketmqPushConsumer);
    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
Also used : Field(java.lang.reflect.Field) MessagingAccessPoint(io.openmessaging.MessagingAccessPoint) DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) Before(org.junit.Before)

Aggregations

MessagingAccessPoint (io.openmessaging.MessagingAccessPoint)14 Field (java.lang.reflect.Field)8 Before (org.junit.Before)8 Message (io.openmessaging.Message)6 MessageListener (io.openmessaging.MessageListener)2 Producer (io.openmessaging.Producer)2 Promise (io.openmessaging.Promise)2 PromiseListener (io.openmessaging.PromiseListener)2 PullConsumer (io.openmessaging.PullConsumer)2 PushConsumer (io.openmessaging.PushConsumer)2 ReceivedMessageContext (io.openmessaging.ReceivedMessageContext)2 SendResult (io.openmessaging.SendResult)2 DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)2 ClientConfig (io.openmessaging.rocketmq.config.ClientConfig)1