• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MessageListenerOrderly类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly的典型用法代码示例。如果您正苦于以下问题:Java MessageListenerOrderly类的具体用法?Java MessageListenerOrderly怎么用?Java MessageListenerOrderly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MessageListenerOrderly类属于com.alibaba.rocketmq.client.consumer.listener包,在下文中一共展示了MessageListenerOrderly类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: ConsumeMessageOrderlyService

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl,
        MessageListenerOrderly messageListener) {
    this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl;
    this.messageListener = messageListener;

    this.defaultMQPushConsumer = this.defaultMQPushConsumerImpl.getDefaultMQPushConsumer();
    this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup();
    this.consumeRequestQueue = new LinkedBlockingQueue<Runnable>();

    this.consumeExecutor = new ThreadPoolExecutor(//
        this.defaultMQPushConsumer.getConsumeThreadMin(),//
        this.defaultMQPushConsumer.getConsumeThreadMax(),//
        1000 * 60,//
        TimeUnit.MILLISECONDS,//
        this.consumeRequestQueue,//
        new ThreadFactoryImpl("ConsumeMessageThread_"));

    this.scheduledExecutorService =
            Executors.newSingleThreadScheduledExecutor(new ThreadFactoryImpl(
                "ConsumeMessageScheduledThread_"));
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:22,代码来源:ConsumeMessageOrderlyService.java


示例2: preProcess

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void preProcess(MessageListenerOrderly t, Object proxy, Method method, Object[] args) {

    List<MessageExt> msgs = (List<MessageExt>) args[0];
    String url = address + "/" + msgs.get(0).getTopic();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, url);
    params.put(CaptureConstants.INFO_CLIENT_REQUEST_ACTION, "Consumer." + method.getName());
    params.put(CaptureConstants.INFO_CLIENT_APPID, applicationId);
    params.put(CaptureConstants.INFO_CLIENT_TYPE, "rabbitmq.client");
    params.put(CaptureConstants.INFO_CAPCONTEXT_TAG, method.getName());

    if (logger.isDebugable()) {
        logger.debug("Invoke START:" + url + ",op=Consumer." + method.getName(), null);
    }

    UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
            Monitor.CapturePhase.PRECAP, params);

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:RocketmqIT.java


示例3: main

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_3");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

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

    consumer.registerMessageListener(new MessageListenerOrderly() {
        AtomicLong consumeTimes = new AtomicLong(0);


        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            context.setAutoCommit(false);
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 2) == 0) {
                return ConsumeOrderlyStatus.SUCCESS;
            }
            else if ((this.consumeTimes.get() % 3) == 0) {
                return ConsumeOrderlyStatus.ROLLBACK;
            }
            else if ((this.consumeTimes.get() % 4) == 0) {
                return ConsumeOrderlyStatus.COMMIT;
            }
            else if ((this.consumeTimes.get() % 5) == 0) {
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }

            return ConsumeOrderlyStatus.SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:39,代码来源:Consumer.java


示例4: testOrderedConsumer

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
@Before
public void testOrderedConsumer() throws Exception {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("example_group_name");

    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

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

    consumer.registerMessageListener(new MessageListenerOrderly() {

        AtomicLong consumeTimes = new AtomicLong(0);

        @SuppressWarnings("deprecation")
        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            context.setAutoCommit(false);
            System.out.printf(Thread.currentThread().getName() + " Receive New Messages: " + msgs + "%n");
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 2) == 0) {
                return ConsumeOrderlyStatus.SUCCESS;
            } else if ((this.consumeTimes.get() % 3) == 0) {
                return ConsumeOrderlyStatus.ROLLBACK;
            } else if ((this.consumeTimes.get() % 4) == 0) {
                return ConsumeOrderlyStatus.COMMIT;
            } else if ((this.consumeTimes.get() % 5) == 0) {
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }
            return ConsumeOrderlyStatus.SUCCESS;

        }
    });

    consumer.start();

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


示例5: getRollBackMessageListener

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
private static MessageListenerOrderly getRollBackMessageListener() {
    return new MessageListenerOrderly() {
        AtomicLong consumeTimes = new AtomicLong(0);


        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            System.out.println("MESSAGE BODY========" + new String(msgs.get(0).getBody()));
            context.setAutoCommit(false);
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 1) == 0) {
                System.out.println("SUCCESS========Receive New Messages: " + msgs);
                return ConsumeOrderlyStatus.SUCCESS;
            }
            else if ((this.consumeTimes.get() % 2) == 0) {
                System.out.println("ROLLBACK========Receive New Messages: " + msgs);
                return ConsumeOrderlyStatus.ROLLBACK;
            }
            else if ((this.consumeTimes.get() % 3) == 0) {
                System.out.println("COMMIT========Receive New Messages: " + msgs);
                return ConsumeOrderlyStatus.COMMIT;
            }
            else if ((this.consumeTimes.get() % 5) == 0) {
                System.out.println("SUSPEND_CURRENT_QUEUE_A_MOMENT========Receive New Messages: "
                        + msgs.get(0));
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }

            return ConsumeOrderlyStatus.SUCCESS;
        }
    };
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:34,代码来源:PushConsumerTest.java


示例6: getAutoCommitMessageListener

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
private static MessageListenerOrderly getAutoCommitMessageListener() {
    return new MessageListenerOrderly() {
        AtomicLong consumeTimes = new AtomicLong(0);


        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            System.out.println("MESSAGE BODY========" + new String(msgs.get(0).getBody()));
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 1) == 0) {
                System.out.println("SUCCESS========Receive New Messages: " + msgs);
                return ConsumeOrderlyStatus.SUCCESS;
            }
            else if ((this.consumeTimes.get() % 2) == 0) {
                System.out.println("ROLLBACK========Receive New Messages: " + msgs);
                return ConsumeOrderlyStatus.ROLLBACK;
            }
            else if ((this.consumeTimes.get() % 5) == 0) {
                System.out.println("SUSPEND_CURRENT_QUEUE_A_MOMENT========Receive New Messages: "
                        + msgs.get(0));
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }

            return ConsumeOrderlyStatus.SUCCESS;
        }
    };
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:29,代码来源:PushConsumerTest.java


示例7: createMessageListener

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
private static MessageListener createMessageListener() {
    return new MessageListenerOrderly() {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            for (MessageExt msg : msgs) {
                System.err.println("topic:" + msg.getTopic() + ", msgId:" + msg.getMsgId() + ", body:"
                        + new String(msg.getBody()));
            }
            return ConsumeOrderlyStatus.SUCCESS;
        }
    };
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:14,代码来源:UnitOrderTest.java


示例8: ConsumeMessageOrderlyService

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
public ConsumeMessageOrderlyService(DefaultMQPushConsumerImpl defaultMQPushConsumerImpl,
        MessageListenerOrderly messageListener) {
    this.defaultMQPushConsumerImpl = defaultMQPushConsumerImpl;
    this.messageListener = messageListener;

    this.defaultMQPushConsumer = this.defaultMQPushConsumerImpl.getDefaultMQPushConsumer();
    this.consumerGroup = this.defaultMQPushConsumer.getConsumerGroup();
    this.consumeRequestQueue = new LinkedBlockingQueue<Runnable>();

    this.consumeExecutor = new ThreadPoolExecutor(//
        this.defaultMQPushConsumer.getConsumeThreadMin(),//
        this.defaultMQPushConsumer.getConsumeThreadMax(),//
        1000 * 60,//
        TimeUnit.MILLISECONDS,//
        this.consumeRequestQueue,//
        new ThreadFactory() {
            private AtomicLong threadIndex = new AtomicLong(0);


            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "ConsumeMessageThread-" //
                        + ConsumeMessageOrderlyService.this.consumerGroup//
                        + "-" + this.threadIndex.incrementAndGet());
            }
        });

    this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r, "ConsumeMessageScheduledThread-" + consumerGroup);
        }
    });
}
 
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:35,代码来源:ConsumeMessageOrderlyService.java


示例9: main

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_3");

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

    consumer.registerMessageListener(new MessageListenerOrderly() {
        AtomicLong consumeTimes = new AtomicLong(0);


        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            context.setAutoCommit(false);
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 2) == 0) {
                return ConsumeOrderlyStatus.SUCCESS;
            }
            else if ((this.consumeTimes.get() % 3) == 0) {
                return ConsumeOrderlyStatus.ROLLBACK;
            }
            else if ((this.consumeTimes.get() % 4) == 0) {
                return ConsumeOrderlyStatus.COMMIT;
            }
            else if ((this.consumeTimes.get() % 5) == 0) {
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }

            return ConsumeOrderlyStatus.SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
开发者ID:brucechan0921,项目名称:RocketMQ-3.0.8,代码行数:37,代码来源:Consumer.java


示例10: registerMessageListener

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
@Override
public void registerMessageListener(MessageListenerOrderly messageListener) {
    this.messageListener = messageListener;
    this.defaultMQPushConsumerImpl.registerMessageListener(messageListener);
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:6,代码来源:DefaultMQPushConsumer.java


示例11: postProcess

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
@Override
public Object postProcess(Object res, MessageListenerOrderly t, Object proxy, Method method, Object[] args) {

    doCap(1, method.getName());
    return null;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:7,代码来源:RocketmqIT.java


示例12: main

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
public static void main(String[] args) throws MQClientException {
    DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("please_rename_unique_group_name_3");
    /**
     * 设置Consumer第一次启动是从队列头部开始消费还是队列尾部开始消费<br>
     * 如果非第一次启动,那么按照上次消费的位置继续消费
     */
    consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);

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

    consumer.registerMessageListener(new MessageListenerOrderly() {
        AtomicLong consumeTimes = new AtomicLong(0);


        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
            context.setAutoCommit(false);
            System.out.println(Thread.currentThread().getName() + " Receive New Messages: " + msgs);
            this.consumeTimes.incrementAndGet();
            if ((this.consumeTimes.get() % 2) == 0) {
                return ConsumeOrderlyStatus.SUCCESS;
            }
            else if ((this.consumeTimes.get() % 3) == 0) {
                return ConsumeOrderlyStatus.ROLLBACK;
            }
            else if ((this.consumeTimes.get() % 4) == 0) {
                return ConsumeOrderlyStatus.COMMIT;
            }
            else if ((this.consumeTimes.get() % 5) == 0) {
                context.setSuspendCurrentQueueTimeMillis(3000);
                return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
            }

            return ConsumeOrderlyStatus.SUCCESS;
        }
    });

    consumer.start();

    System.out.println("Consumer Started.");
}
 
开发者ID:diwayou,项目名称:rocketmq-all-trans,代码行数:42,代码来源:Consumer.java


示例13: catchInvokeException

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
@Override
public void catchInvokeException(MessageListenerOrderly t, Object proxy, Method method, Object[] args,
        Throwable e) {

    doCap(0, method.getName());

}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:8,代码来源:RocketmqIT.java


示例14: registerMessageListener

import com.alibaba.rocketmq.client.consumer.listener.MessageListenerOrderly; //导入依赖的package包/类
void registerMessageListener(final MessageListenerOrderly messageListener); 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:2,代码来源:MQPushConsumer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SlideInRightAnimator类代码示例发布时间:2022-05-23
下一篇:
Java Converter类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap