码迷,mamicode.com
首页 > 其他好文 > 详细

rocketmq消费队列代码

时间:2015-07-14 11:31:43      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(Constant.operationLogGroup);
        try {
            consumer.setNamesrvAddr(Constant.rocketQueneAddr);
            consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
            consumer.setMessageModel(MessageModel.BROADCASTING);
            consumer.subscribe(Constant.operationLogTopic, Constant.operationLogTag);
        } catch (MQClientException e) {
            logger.error("consume operation log MQ error", e);
        }

        cometutil = Comet4jUtil.getInstance(CHANNEL);

        consumer.registerMessageListener(new MessageListenerConcurrently() {

            @Override
            public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {

                byte[] bytes = msgs.get(0).getBody();
                try {
                    cometutil.sendMesToAllConnsWithString(CHANNEL, new String(bytes, "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                }
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
            }
        });

        try {
            consumer.start();
            logger.info("operationLogController‘s MQ consumer started.");
        } catch (MQClientException e) {
            logger.error("consume operation log MQ start error", e);
        }

版权声明:本文为博主原创文章,未经博主允许不得转载。

rocketmq消费队列代码

标签:

原文地址:http://blog.csdn.net/ro_wsy/article/details/46874267

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!