io.openmessaging.consumer.PullConsumer Java Examples

The following examples show how to use io.openmessaging.consumer.PullConsumer. 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: PullConsumerApp.java    From openmessaging-java with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    //Load and start the vendor implementation from a specific OMS driver URL.
    final MessagingAccessPoint messagingAccessPoint =
        OMS.getMessagingAccessPoint("oms:rocketmq://[email protected]/us-east");

    //Start a PullConsumer to receive messages from the specific queue.
    final PullConsumer consumer = messagingAccessPoint.createPullConsumer();

    //Register a shutdown hook to close the opened endpoints.
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            consumer.stop();
        }
    }));

    consumer.bindQueue(Arrays.asList("NS://HELLO_QUEUE"));
    consumer.start();

    Message message = consumer.receive(1000);
    System.out.println("Received message: " + message);
    //Acknowledge the consumed message
    consumer.ack(message.getMessageReceipt());
    consumer.stop();

}
 
Example #2
Source File: WorkerSinkTask.java    From openmessaging-connect-runtime with Apache License 2.0 5 votes vote down vote up
public WorkerSinkTask(String connectorName,
                      SinkTask sinkTask,
                      ConnectKeyValue taskConfig,
                      Converter recordConverter,
                      PullConsumer consumer) {
    this.connectorName = connectorName;
    this.sinkTask = sinkTask;
    this.taskConfig = taskConfig;
    this.isStopping = new AtomicBoolean(false);
    this.consumer = consumer;
    this.recordConverter = recordConverter;
}
 
Example #3
Source File: MessagingAccessPointImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer(KeyValue attributes) {
    return new PullConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, attributes));
}
 
Example #4
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 #5
Source File: MessagingAccessPointImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer() {
    return new PullConsumerImpl(accessPointProperties);
}
 
Example #6
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer detachQueue(String queueName) {
    this.rocketmqPullConsumer.getRegisterTopics().remove(queueName);
    return this;
}
 
Example #7
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName, KeyValue attributes) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #8
Source File: PullConsumerImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #9
Source File: SimplePullConsumer.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");

    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 #10
Source File: MessagingAccessPointAdapterTest.java    From openmessaging-java with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer(KeyValue attributes) {
    return null;
}
 
Example #11
Source File: MessagingAccessPointAdapterTest.java    From openmessaging-java with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer() {
    return null;
}
 
Example #12
Source File: MessagingAccessPointImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer(KeyValue attributes) {
    return new PullConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, attributes));
}
 
Example #13
Source File: MessagingAccessPointImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer() {
    return new PullConsumerImpl(accessPointProperties);
}
 
Example #14
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer detachQueue(String queueName) {
    this.rocketmqPullConsumer.getRegisterTopics().remove(queueName);
    return this;
}
 
Example #15
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName, KeyValue attributes) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #16
Source File: PullConsumerImpl.java    From rocketmq-read with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #17
Source File: SimplePullConsumer.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");

    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 #18
Source File: MessagingAccessPointImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer(KeyValue attributes) {
    return new PullConsumerImpl(OMSUtil.buildKeyValue(this.accessPointProperties, attributes));
}
 
Example #19
Source File: MessagingAccessPointImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer createPullConsumer() {
    return new PullConsumerImpl(accessPointProperties);
}
 
Example #20
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer detachQueue(String queueName) {
    this.rocketmqPullConsumer.getRegisterTopics().remove(queueName);
    return this;
}
 
Example #21
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName, KeyValue attributes) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #22
Source File: PullConsumerImpl.java    From rocketmq-4.3.0 with Apache License 2.0 4 votes vote down vote up
@Override
public PullConsumer attachQueue(String queueName) {
    registerPullTaskCallback(queueName);
    return this;
}
 
Example #23
Source File: MessagingAccessPoint.java    From openmessaging-java with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code PullConsumer} for the specified {@code MessagingAccessPoint}.
 *
 * @return the created {@code PullConsumer}
 * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request
 * due to some internal error
 */
PullConsumer createPullConsumer();
 
Example #24
Source File: MessagingAccessPoint.java    From openmessaging-java with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@code PullConsumer} for the specified {@code MessagingAccessPoint}.
 *
 * @return the created {@code PullConsumer}
 * @throws OMSRuntimeException if the {@code MessagingAccessPoint} fails to handle this request
 * due to some internal error
 */
PullConsumer createPullConsumer(KeyValue attributes);