Package com.alibaba.rocketmq.common.message

Examples of com.alibaba.rocketmq.common.message.MessageQueue


            if (!UtilAll.isBlank(projectGroupPrefix)) {
                HashMap<MessageQueue, OffsetWrapper> newTopicOffsetMap =
                        new HashMap<MessageQueue, OffsetWrapper>();
                for (Map.Entry<MessageQueue, OffsetWrapper> messageQueue : consumeStats.getOffsetTable()
                    .entrySet()) {
                    MessageQueue key = messageQueue.getKey();
                    key.setTopic(VirtualEnvUtil.clearProjectGroup(key.getTopic(), projectGroupPrefix));
                    newTopicOffsetMap.put(key, messageQueue.getValue());
                }
                consumeStats.setOffsetTable(newTopicOffsetMap);
            }
View Full Code Here


            String[] brokers = route.getOrderTopicConf().split(";");
            for (String broker : brokers) {
                String[] item = broker.split(":");
                int nums = Integer.parseInt(item[1]);
                for (int i = 0; i < nums; i++) {
                    MessageQueue mq = new MessageQueue(topic, item[0], i);
                    info.getMessageQueueList().add(mq);
                }
            }

            info.setOrderTopic(true);
        }
        // 非顺序消息
        else {
            List<QueueData> qds = route.getQueueDatas();
            // 排序原因:即使没有配置顺序消息模式,默认队列的顺序同配置的一致。
            Collections.sort(qds);
            for (QueueData qd : qds) {
                if (PermName.isWriteable(qd.getPerm())) {
                    // 这里需要判断BrokerName对应的Master是否存在,因为只能向Master发送消息
                    BrokerData brokerData = null;
                    for (BrokerData bd : route.getBrokerDatas()) {
                        if (bd.getBrokerName().equals(qd.getBrokerName())) {
                            brokerData = bd;
                            break;
                        }
                    }

                    if (null == brokerData) {
                        continue;
                    }

                    if (!brokerData.getBrokerAddrs().containsKey(MixAll.MASTER_ID)) {
                        continue;
                    }

                    for (int i = 0; i < qd.getWriteQueueNums(); i++) {
                        MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i);
                        info.getMessageQueueList().add(mq);
                    }
                }
            }
View Full Code Here

        Set<MessageQueue> mqList = new HashSet<MessageQueue>();
        List<QueueData> qds = route.getQueueDatas();
        for (QueueData qd : qds) {
            if (PermName.isReadable(qd.getPerm())) {
                for (int i = 0; i < qd.getReadQueueNums(); i++) {
                    MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i);
                    mqList.add(mq);
                }
            }
        }
View Full Code Here

            // consumerRequest 处理结束并销毁
            ConcurrentHashMap<MessageQueue, ProcessQueue> processQueueTable =
                    consumer.getRebalanceImpl().getProcessQueueTable();
            Iterator<MessageQueue> itr = processQueueTable.keySet().iterator();
            while (itr.hasNext()) {
                MessageQueue mq = itr.next();
                if (topic.equals(mq.getTopic())) {
                    ProcessQueue pq = processQueueTable.get(mq);
                    pq.setDroped(true);
                    pq.clear();
                }
            }

            // 更新消费队列的 offset 并提交到 broker
            Iterator<MessageQueue> iterator = offsetTable.keySet().iterator();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                consumer.updateConsumeOffset(mq, offsetTable.get(mq));
                log.info("[reset-offset] reset offsetTable. topic={}, group={}, mq={}, offset={}",
                    new Object[] { topic, group, mq, offsetTable.get(mq) });
            }
            consumer.getOffsetStore().persistAll(offsetTable.keySet());

            // 等待所有的 pullRequest 以及 consumerRequest 处理完成
            try {
                TimeUnit.SECONDS.sleep(10);
            }
            catch (InterruptedException e) {
                //
            }

            // 更新消费队列的 offset 并提交到 broker
            iterator = offsetTable.keySet().iterator();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                consumer.updateConsumeOffset(mq, offsetTable.get(mq));
                log.info("[reset-offset] reset offsetTable. topic={}, group={}, mq={}, offset={}",
                    new Object[] { topic, group, mq, offsetTable.get(mq) });
            }
            consumer.getOffsetStore().persistAll(offsetTable.keySet());

            // 真正清除被 dropped 的 processQueue,从而使得新的 rebalance 生效,生成新的 pullRequest
            // 以及 consumerRequest
            iterator = offsetTable.keySet().iterator();
            processQueueTable = consumer.getRebalanceImpl().getProcessQueueTable();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                processQueueTable.remove(mq);
            }
        }
        finally {
            // 放在 finally 主要是确保 rebalance 一定被执行
View Full Code Here

    public static void main(String[] args) throws MQClientException {
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("please_rename_unique_group_name_5");
        consumer.start();

        try {
            MessageQueue mq = new MessageQueue();
            mq.setQueueId(0);
            mq.setTopic("TopicTest3");
            mq.setBrokerName("vivedeMacBook-Pro.local");

            long offset = 26;

            long beginTime = System.currentTimeMillis();
            PullResult pullResult = consumer.pullBlockIfNotFound(mq, null, offset, 32);
View Full Code Here

        final long beginTimestamp = System.currentTimeMillis();
        long endTimestamp = beginTimestamp;
        TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
        if (topicPublishInfo != null && topicPublishInfo.ok()) {
            MessageQueue mq = null;
            Exception exception = null;
            SendResult sendResult = null;
            int timesTotal = 1 + this.defaultMQProducer.getRetryTimesWhenSendFailed();
            for (int times = 0; times < timesTotal
                    && (endTimestamp - beginTimestamp) < this.defaultMQProducer.getSendMsgTimeout(); times++) {
                String lastBrokerName = null == mq ? null : mq.getBrokerName();
                MessageQueue tmpmq = topicPublishInfo.selectOneMessageQueue(lastBrokerName);
                if (tmpmq != null) {
                    mq = tmpmq;
                    try {
                        sendResult = this.sendKernelImpl(msg, mq, communicationMode, sendCallback);
                        endTimestamp = System.currentTimeMillis();
View Full Code Here

        this.makeSureStateOK();
        Validators.checkMessage(msg, this.defaultMQProducer);

        TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());
        if (topicPublishInfo != null && topicPublishInfo.ok()) {
            MessageQueue mq = null;
            try {
                mq = selector.select(topicPublishInfo.getMessageQueueList(), msg, arg);
            }
            catch (Throwable e) {
                throw new MQClientException("select message queue throwed exception.", e);
View Full Code Here

            String[] brokers = route.getOrderTopicConf().split(";");
            for (String broker : brokers) {
                String[] item = broker.split(":");
                int nums = Integer.parseInt(item[1]);
                for (int i = 0; i < nums; i++) {
                    MessageQueue mq = new MessageQueue(topic, item[0], i);
                    info.getMessageQueueList().add(mq);
                }
            }

            info.setOrderTopic(true);
        }
        // 非顺序消息
        else {
            List<QueueData> qds = route.getQueueDatas();
            // 排序原因:即使没有配置顺序消息模式,默认队列的顺序同配置的一致。
            Collections.sort(qds);
            for (QueueData qd : qds) {
                if (PermName.isWriteable(qd.getPerm())) {
                    // 这里需要判断BrokerName对应的Master是否存在,因为只能向Master发送消息
                    BrokerData brokerData = null;
                    for (BrokerData bd : route.getBrokerDatas()) {
                        if (bd.getBrokerName().equals(qd.getBrokerName())) {
                            brokerData = bd;
                            break;
                        }
                    }

                    if (null == brokerData) {
                        continue;
                    }

                    if (!brokerData.getBrokerAddrs().containsKey(MixAll.MASTER_ID)) {
                        continue;
                    }

                    for (int i = 0; i < qd.getWriteQueueNums(); i++) {
                        MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i);
                        info.getMessageQueueList().add(mq);
                    }
                }
            }
View Full Code Here

        Set<MessageQueue> mqList = new HashSet<MessageQueue>();
        List<QueueData> qds = route.getQueueDatas();
        for (QueueData qd : qds) {
            if (PermName.isReadable(qd.getPerm())) {
                for (int i = 0; i < qd.getReadQueueNums(); i++) {
                    MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i);
                    mqList.add(mq);
                }
            }
        }
View Full Code Here

            // consumerRequest 处理结束并销毁
            ConcurrentHashMap<MessageQueue, ProcessQueue> processQueueTable =
                    consumer.getRebalanceImpl().getProcessQueueTable();
            Iterator<MessageQueue> itr = processQueueTable.keySet().iterator();
            while (itr.hasNext()) {
                MessageQueue mq = itr.next();
                if (topic.equals(mq.getTopic())) {
                    ProcessQueue pq = processQueueTable.get(mq);
                    pq.setDroped(true);
                    pq.clear();
                }
            }

            // 更新消费队列的 offset 并提交到 broker
            Iterator<MessageQueue> iterator = offsetTable.keySet().iterator();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                consumer.updateConsumeOffset(mq, offsetTable.get(mq));
                log.info("[reset-offset] reset offsetTable. topic={}, group={}, mq={}, offset={}",
                    new Object[] { topic, group, mq, offsetTable.get(mq) });
            }
            consumer.getOffsetStore().persistAll(offsetTable.keySet());

            // 等待所有的 pullRequest 以及 consumerRequest 处理完成
            try {
                TimeUnit.SECONDS.sleep(10);
            }
            catch (InterruptedException e) {
                //
            }

            // 更新消费队列的 offset 并提交到 broker
            iterator = offsetTable.keySet().iterator();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                consumer.updateConsumeOffset(mq, offsetTable.get(mq));
                log.info("[reset-offset] reset offsetTable. topic={}, group={}, mq={}, offset={}",
                    new Object[] { topic, group, mq, offsetTable.get(mq) });
            }
            consumer.getOffsetStore().persistAll(offsetTable.keySet());

            // 真正清除被 dropped 的 processQueue,从而使得新的 rebalance 生效,生成新的 pullRequest
            // 以及 consumerRequest
            iterator = offsetTable.keySet().iterator();
            processQueueTable = consumer.getRebalanceImpl().getProcessQueueTable();
            while (iterator.hasNext()) {
                MessageQueue mq = iterator.next();
                processQueueTable.remove(mq);
            }
        }
        finally {
            // 放在 finally 主要是确保 rebalance 一定被执行
View Full Code Here

TOP

Related Classes of com.alibaba.rocketmq.common.message.MessageQueue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.