Java Code Examples for io.openmessaging.consumer.PullConsumer#attachQueue()
The following examples show how to use
io.openmessaging.consumer.PullConsumer#attachQueue() .
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: SimplePullConsumer.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
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 2
Source File: SimplePullConsumer.java From rocketmq-read with Apache License 2.0 | 4 votes |
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 3
Source File: SimplePullConsumer.java From rocketmq with Apache License 2.0 | 4 votes |
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(); }