当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMQPushConsumer.subscribe方法代码示例

本文整理汇总了Java中org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMQPushConsumer.subscribe方法的具体用法?Java DefaultMQPushConsumer.subscribe怎么用?Java DefaultMQPushConsumer.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.rocketmq.client.consumer.DefaultMQPushConsumer的用法示例。


在下文中一共展示了DefaultMQPushConsumer.subscribe方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receiveTransactionMessage

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
 * 接收消息
 */
public void receiveTransactionMessage() {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
    consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    consumer.setVipChannelEnabled(false);
    consumer.setConsumeThreadMax(20);
    consumer.setConsumeThreadMin(10);
    try {
        consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "transaction");
        //程序第一次启动从消息队列头取数据
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.registerMessageListener(
                new MessageListenerConcurrently() {
                    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
                        Message msg = list.get(0);
                        System.out.println(msg.toString());
                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                    }
                }
        );
        consumer.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:28,代码来源:RocketMQTransactionConsumer.java

示例2: receiveMessage

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
 * 接收消息
 */
public void receiveMessage(){
    DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
    consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    consumer.setVipChannelEnabled(false);
    try {
        consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "schedule");
        //程序第一次启动从消息队列头取数据
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.registerMessageListener(
                new MessageListenerConcurrently() {
                    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,ConsumeConcurrentlyContext Context) {
                        Message msg = list.get(0);
                        System.out.println(msg.toString());
                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                    }
                }
        );
        consumer.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:26,代码来源:RocketMQScheduleConsumer.java

示例3: receiveMessage

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
 * 接收消息
 */
public void receiveMessage(){
    DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
    consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    consumer.setVipChannelEnabled(false);
    try {
        consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, "bactch");
        //程序第一次启动从消息队列头取数据
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.registerMessageListener(
                new MessageListenerConcurrently() {
                    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list,ConsumeConcurrentlyContext Context) {
                        Message msg = list.get(0);
                        System.out.println(msg.toString());
                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                    }
                }
        );
        consumer.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:26,代码来源:RocketMQBatchConsumer.java

示例4: receiveFilterMessage

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
/**
 * 接收消息
 */
public void receiveFilterMessage(){
    DefaultMQPushConsumer consumer =new DefaultMQPushConsumer(RocketMQConfiguration.ROCKETMQ_GROUP);
    consumer.setNamesrvAddr(RocketMQConfiguration.ROCKETMQ_NAMESRV);
    consumer.setVipChannelEnabled(false);
    try {
        consumer.subscribe(RocketMQConfiguration.ROCKETMQ_TOPIC, MessageSelector.bySql("a between 5 and 8"));
        //程序第一次启动从消息队列头取数据
        consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.registerMessageListener(
                new MessageListenerConcurrently() {
                    public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext Context) {
                        Message msg = list.get(0);
                        System.out.println(msg.toString());
                        return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                    }
                }
        );
        consumer.start();
    } catch (MQClientException e) {
        e.printStackTrace();
    }
}
 
开发者ID:mumudemo,项目名称:mumu-rocketmq,代码行数:26,代码来源:RocketMQFilterConsumer.java

示例5: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_1");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.setMessageModel(MessageModel.BROADCASTING);

    consumer.subscribe("TopicTest", "TagA || TagC || TagD");

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
            ConsumeConcurrentlyContext context) {
            System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();
    System.out.printf("Broadcast Consumer Started.%n");
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:23,代码来源:PushConsumer.java

示例6: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile());

    String filterCode = MixAll.file2String(classFile);
    consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl",
        filterCode);

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
            ConsumeConcurrentlyContext context) {
            System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.printf("Consumer Started.%n");
}
 
开发者ID:lyy4j,项目名称:rmq4note,代码行数:25,代码来源:Consumer.java

示例7: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException, IOException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile());

    String filterCode = MixAll.file2String(classFile);
    consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl",
        filterCode);

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
            ConsumeConcurrentlyContext context) {
            System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();

    System.out.printf("Consumer Started.%n");
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:Consumer.java

示例8: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("broadcast_consumer_group");
    consumer.setNamesrvAddr("127.0.0.1:9876");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.setMessageModel(MessageModel.BROADCASTING);

    consumer.subscribe("TopicTest", "TagA || TagC || TagD");

    consumer.registerMessageListener(new MessageListenerConcurrently() {

        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs,
                                                        ConsumeConcurrentlyContext context) {
            System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });

    consumer.start();
    System.out.printf("Broadcast Consumer Started.%n");
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:24,代码来源:PushConsumer.java

示例9: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("order_message_consumer_group");
    consumer.setNamesrvAddr("127.0.0.1:9876");
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.subscribe("TopicTest", "TagA || TagC || TagD");

    // 顺序消费特点:不会有两个消费者共同消费任一队列,且当消费者数量小于队列数时,消费者会消费多个队列
    consumer.registerMessageListener(new MessageListenerOrderly() {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            //context.setAutoCommit(false);
            System.out.printf(System.currentTimeMillis() + "," + Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");

            return ConsumeOrderlyStatus.SUCCESS;
        }
    });

    consumer.start();
    System.out.printf("Consumer Started.%n");
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:23,代码来源:Consumer.java

示例10: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("push_consumer_group");
    consumer.setNamesrvAddr("127.0.0.1:9876");
    consumer.subscribe("TopicTest", "*");
    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(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    consumer.start();
    System.out.printf("Consumer Started.%n");
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:22,代码来源:PushConsumer.java

示例11: testConsumer

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Test
public void testConsumer() {
    DefaultMQPushConsumer consumer =
            new DefaultMQPushConsumer("PushConsumer");
    consumer.setNamesrvAddr("192.168.146.109:9876");
    try {
        //订阅PushTopic下Tag为push的消息
        consumer.subscribe("PushTopic", "push");
        //程序第一次启动从消息队列头取数据
        consumer.setConsumeFromWhere(
                ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
        consumer.registerMessageListener(
                (MessageListenerConcurrently) (list, Context) -> {
                    Message msg = list.get(0);
                    System.out.println(msg.toString());
                    return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                }
        );
        consumer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:24,代码来源:TcRocketmqTest.java

示例12: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_1");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

    consumer.setMessageModel(MessageModel.BROADCASTING);

    consumer.subscribe("TopicTest", "TagA || TagC || TagD");

    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("Broadcast Consumer Started.%n");
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:23,代码来源:PushConsumer.java

示例13: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
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");
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:18,代码来源:PushConsumer.java

示例14: main

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, MQClientException, IOException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ConsumerGroupNamecc4");

    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    File classFile = new File(classLoader.getResource("MessageFilterImpl.java").getFile());

    String filterCode = MixAll.file2String(classFile);
    consumer.subscribe("TopicTest", "org.apache.rocketmq.example.filter.MessageFilterImpl",
        filterCode);

    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");
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:25,代码来源:Consumer.java

示例15: test

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; //导入方法依赖的package包/类
@Test
public void test() throws Exception {

    RocketmqMessageConsumerListener messageConsumerListener = new RocketmqMessageConsumerListener();

    messageConsumerListener.setModel("MODEL_1");
    messageConsumerListener.setBatch("NON_BATCH");
    messageConsumerListener.setMessageDecoder(new RocketmqMessageDecoderDemo());
    messageConsumerListener.setConsumer(new MessageConsumer());

    DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer();

    defaultMQPushConsumer.setNamesrvAddr("localhost:9876");
    defaultMQPushConsumer.setConsumerGroup("contest");
    defaultMQPushConsumer.subscribe("QUEUE_TEST", "*");
    defaultMQPushConsumer.setMessageListener(messageConsumerListener.getMessageListener());

    defaultMQPushConsumer.start();
}
 
开发者ID:DarkPhoenixs,项目名称:message-queue-client-framework,代码行数:20,代码来源:ConsumerTest.java


注:本文中的org.apache.rocketmq.client.consumer.DefaultMQPushConsumer.subscribe方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。