Java Code Examples for io.openmessaging.MessagingAccessPoint#startup()

The following examples show how to use io.openmessaging.MessagingAccessPoint#startup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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);
    field.set(consumer, rocketmqPullConsumer); //Replace

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setOmsOperationTimeout(200);
    localMessageCache = spy(new LocalMessageCache(rocketmqPullConsumer, clientConfig));

    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);

    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example 2
Source File: PushConsumerImplTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(
        OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "TestGroup"));

    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example 3
Source File: PushConsumerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://IP1:9876,IP2:9876/namespace");
    consumer = messagingAccessPoint.createPushConsumer(
        OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "TestGroup"));

    Field field = PushConsumerImpl.class.getDeclaredField("rocketmqPushConsumer");
    field.setAccessible(true);
    DefaultMQPushConsumer innerConsumer = (DefaultMQPushConsumer) field.get(consumer);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example 4
Source File: PushConsumerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@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);
    field.set(consumer, rocketmqPushConsumer); //Replace

    when(rocketmqPushConsumer.getMessageListener()).thenReturn(innerConsumer.getMessageListener());
    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example 5
Source File: PullConsumerImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@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);
    field.set(consumer, rocketmqPullConsumer); //Replace

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setOmsOperationTimeout(200);
    localMessageCache = spy(new LocalMessageCache(rocketmqPullConsumer, clientConfig));

    field = PullConsumerImpl.class.getDeclaredField("localMessageCache");
    field.setAccessible(true);
    field.set(consumer, localMessageCache);

    messagingAccessPoint.startup();
    consumer.startup();
}
 
Example 6
Source File: SimplePushConsumer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example 7
Source File: SequenceProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createSequenceProducer();

    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);

    messagingAccessPoint.startup();
    producer.startup();
}
 
Example 8
Source File: SimplePushConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example 9
Source File: ProducerImplTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms: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();
}
 
Example 10
Source File: ProducerImplTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 11
Source File: SequenceProducerImplTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = MessagingAccessPointFactory
        .getMessagingAccessPoint("openmessaging:rocketmq://IP1:9876,IP2:9876/namespace");
    producer = messagingAccessPoint.createSequenceProducer();

    Field field = AbstractOMSProducer.class.getDeclaredField("rocketmqProducer");
    field.setAccessible(true);
    field.set(producer, rocketmqProducer);

    messagingAccessPoint.startup();
    producer.startup();
}
 
Example 12
Source File: SimplePushConsumer.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final PushConsumer consumer = messagingAccessPoint.
        createPushConsumer(OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "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 onReceived(Message message, Context context) {
            System.out.printf("Received one message: %s%n", message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID));
            context.ack();
        }
    });

    consumer.startup();
    System.out.printf("Consumer startup OK%n");
}
 
Example 13
Source File: ProducerImplTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms: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();
}
 
Example 14
Source File: ProducerImplTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws NoSuchFieldException, IllegalAccessException {
    final MessagingAccessPoint messagingAccessPoint = OMS
        .getMessagingAccessPoint("oms: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();
}
 
Example 15
Source File: SimplePushConsumer.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 16
Source File: MessagingAccessWrapper.java    From openmessaging-connect-runtime with Apache License 2.0 5 votes vote down vote up
/**
 * Get a MessagingAccessPoint instance. If it not contained in the memory, create it.
 * @param omsDriverUrl
 * @return
 */
public MessagingAccessPoint getMessageAccessPoint(String omsDriverUrl){

    if(!accessPointMap.containsKey(omsDriverUrl)){
        MessagingAccessPoint messagingAccessPoint = OMS.getMessagingAccessPoint(omsDriverUrl);
        messagingAccessPoint.startup();
        accessPointMap.put(omsDriverUrl, messagingAccessPoint);
    }
    return accessPointMap.get(omsDriverUrl);
}
 
Example 17
Source File: SimplePushConsumer.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
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");
}
 
Example 18
Source File: SimplePullConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint =
        OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    messagingAccessPoint.startup();

    final Producer producer = messagingAccessPoint.createProducer();

    final PullConsumer consumer = messagingAccessPoint.createPullConsumer(
        OMS.newKeyValue().put(OMSBuiltinKeys.CONSUMER_ID, "OMS_CONSUMER"));

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    final String queueName = "TopicTest";

    producer.startup();
    Message msg = producer.createBytesMessage(queueName, "Hello Open Messaging".getBytes());
    SendResult sendResult = producer.send(msg);
    System.out.printf("Send Message OK. MsgId: %s%n", sendResult.messageId());
    producer.shutdown();

    consumer.attachQueue(queueName);

    consumer.startup();
    System.out.printf("Consumer startup OK%n");

    // Keep running until we find the one that has just been sent
    boolean stop = false;
    while (!stop) {
        Message message = consumer.receive();
        if (message != null) {
            String msgId = message.sysHeaders().getString(Message.BuiltinKeys.MESSAGE_ID);
            System.out.printf("Received one message: %s%n", msgId);
            consumer.ack(msgId);

            if (!stop) {
                stop = msgId.equalsIgnoreCase(sendResult.messageId());
            }

        } else {
            System.out.printf("Return without any message%n");
        }
    }

    consumer.shutdown();
    messagingAccessPoint.shutdown();
}
 
Example 19
Source File: SimpleProducer.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint =
        OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final Producer producer = messagingAccessPoint.createProducer();

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    producer.startup();
    System.out.printf("Producer startup OK%n");

    {
        Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")));
        SendResult sendResult = producer.send(message);
        //final Void aVoid = result.get(3000L);
        System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId());
    }

    final CountDownLatch countDownLatch = new CountDownLatch(1);
    {
        final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
        result.addListener(new FutureListener<SendResult>() {
            @Override
            public void operationComplete(Future<SendResult> future) {
                if (future.getThrowable() != null) {
                    System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage());
                } else {
                    System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId());
                }
                countDownLatch.countDown();
            }
        });
    }

    {
        producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
        System.out.printf("Send oneway message OK%n");
    }

    try {
        countDownLatch.await();
        Thread.sleep(500); // Wait some time for one-way delivery.
    } catch (InterruptedException ignore) {
    }

    producer.shutdown();
}
 
Example 20
Source File: SimpleProducer.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    final MessagingAccessPoint messagingAccessPoint =
        OMS.getMessagingAccessPoint("oms:rocketmq://localhost:9876/default:default");

    final Producer producer = messagingAccessPoint.createProducer();

    messagingAccessPoint.startup();
    System.out.printf("MessagingAccessPoint startup OK%n");

    producer.startup();
    System.out.printf("Producer startup OK%n");

    {
        Message message = producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8")));
        SendResult sendResult = producer.send(message);
        //final Void aVoid = result.get(3000L);
        System.out.printf("Send async message OK, msgId: %s%n", sendResult.messageId());
    }

    final CountDownLatch countDownLatch = new CountDownLatch(1);
    {
        final Future<SendResult> result = producer.sendAsync(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
        result.addListener(new FutureListener<SendResult>() {
            @Override
            public void operationComplete(Future<SendResult> future) {
                if (future.getThrowable() != null) {
                    System.out.printf("Send async message Failed, error: %s%n", future.getThrowable().getMessage());
                } else {
                    System.out.printf("Send async message OK, msgId: %s%n", future.get().messageId());
                }
                countDownLatch.countDown();
            }
        });
    }

    {
        producer.sendOneway(producer.createBytesMessage("OMS_HELLO_TOPIC", "OMS_HELLO_BODY".getBytes(Charset.forName("UTF-8"))));
        System.out.printf("Send oneway message OK%n");
    }

    try {
        countDownLatch.await();
        Thread.sleep(500); // Wait some time for one-way delivery.
    } catch (InterruptedException ignore) {
    }

    producer.shutdown();
}