Java Code Examples for org.apache.rocketmq.client.consumer.DefaultMQPushConsumer#shutdown()

The following examples show how to use org.apache.rocketmq.client.consumer.DefaultMQPushConsumer#shutdown() . 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: PushConsumer.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("CID_JODIE_1");
    consumer.subscribe("Jodie_topic_1023", "*");
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
    //wrong time format 2017_0422_221800
    consumer.setConsumeTimestamp("20170422221800");
    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
            System.out.printf("%s Receive New Messages: %s %n", Thread.currentThread().getName(), msgs);
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    consumer.start();
    System.out.printf("Consumer Started.%n");
    consumer.shutdown();
}
 
Example 2
Source File: AbstractTestCase.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
protected int consumeMessages(int count,final String key,int timeout) throws MQClientException, InterruptedException {

        final AtomicInteger cc = new AtomicInteger(0);
        final CountDownLatch countDownLatch = new CountDownLatch(count);

        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("hello");
        consumer.setNamesrvAddr(nameServer);
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.subscribe(topic, "*");

        consumer.registerMessageListener(new MessageListenerConcurrently() {

            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                                                            ConsumeConcurrentlyContext context) {
                for (MessageExt msg : msgs) {
                    String body = new String(msg.getBody());
                    if(key==null||body.contains(key)){
                        countDownLatch.countDown();
                        cc.incrementAndGet();
                        continue;
                    }
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });
        consumer.start();
        countDownLatch.await(timeout, TimeUnit.SECONDS);
        consumer.shutdown();
        return cc.get();
    }
 
Example 3
Source File: RocketmqOfflineInfoHelper.java    From netty-chat with Apache License 2.0 4 votes vote down vote up
@Override
public void unregisterPull(Channel channel) {
    DefaultMQPushConsumer consumer = consumers.get(channel);
    consumer.shutdown();
    consumers.remove(channel);
}