Search in sources :

Example 46 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.

the class DefaultMQAdminExtImpl method cloneGroupOffset.

@Override
public void cloneGroupOffset(String srcGroup, String destGroup, String topic, boolean isOffline) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    String retryTopic = MixAll.getRetryTopic(srcGroup);
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic);
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            this.mqClientInstance.getMQClientAPIImpl().cloneGroupOffset(addr, srcGroup, destGroup, topic, isOffline, timeoutMillis * 3);
        }
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 47 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.

the class DefaultMQAdminExtImpl method resetOffsetByTimestamp.

public Map<MessageQueue, Long> resetOffsetByTimestamp(String topic, String group, long timestamp, boolean isForce, boolean isC) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    Map<MessageQueue, Long> allOffsetTable = new HashMap<MessageQueue, Long>();
    if (brokerDatas != null) {
        for (BrokerData brokerData : brokerDatas) {
            String addr = brokerData.selectBrokerAddr();
            if (addr != null) {
                Map<MessageQueue, Long> offsetTable = this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToResetOffset(addr, topic, group, timestamp, isForce, timeoutMillis, isC);
                if (offsetTable != null) {
                    allOffsetTable.putAll(offsetTable);
                }
            }
        }
    }
    return allOffsetTable;
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) HashMap(java.util.HashMap) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 48 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.

the class DefaultMQAdminExtImpl method examineConsumeStats.

@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    String retryTopic = MixAll.getRetryTopic(consumerGroup);
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(retryTopic);
    ConsumeStats result = new ConsumeStats();
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            ConsumeStats consumeStats = this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, topic, timeoutMillis * 3);
            result.getOffsetTable().putAll(consumeStats.getOffsetTable());
            double value = result.getConsumeTps() + consumeStats.getConsumeTps();
            result.setConsumeTps(value);
        }
    }
    if (result.getOffsetTable().isEmpty()) {
        throw new MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "Not found the consumer group consume stats, because return offset table is empty, maybe the consumer not consume any message");
    }
    return result;
}
Also used : ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 49 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq by apache.

the class DefaultMQAdminExtImpl method examineTopicStats.

@Override
public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    TopicStatsTable topicStatsTable = new TopicStatsTable();
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            TopicStatsTable tst = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis);
            topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable());
        }
    }
    if (topicStatsTable.getOffsetTable().isEmpty()) {
        throw new MQClientException("Not found the topic stats info", null);
    }
    return topicStatsTable;
}
Also used : TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 50 with BrokerData

use of org.apache.rocketmq.common.protocol.route.BrokerData in project rocketmq-externals by apache.

the class RmqSourceReplicator method buildRoute.

public void buildRoute() {
    List<Pattern> patterns = new ArrayList<Pattern>();
    String srcCluster = this.replicatorConfig.getSrcCluster();
    try {
        Set<String> targetTopicSet = fetchTargetTopics();
        for (String topic : this.replicatorConfig.getWhiteList()) {
            Pattern pattern = Pattern.compile(topic);
            patterns.add(pattern);
        }
        TopicList topics = srcMQAdminExt.fetchAllTopicList();
        for (String topic : topics.getTopicList()) {
            if (topic.equals(ConfigDefine.CONN_STORE_TOPIC)) {
                continue;
            }
            if (!syncRETRY && topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            if (!syncDLQ && topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            for (Pattern pattern : patterns) {
                Matcher matcher = pattern.matcher(topic);
                if (matcher.matches()) {
                    String targetTopic = generateTargetTopic(topic);
                    if (!targetTopicSet.contains(targetTopic)) {
                        ensureTargetTopic(topic, targetTopic);
                    }
                    // different from BrokerData with cluster field, which can ensure the brokerData is from expected cluster.
                    // QueueData use brokerName as unique info on cluster of rocketmq. so when we want to get QueueData of
                    // expected cluster, we should get brokerNames of expected cluster, and then filter queueDatas.
                    List<BrokerData> brokerList = Utils.examineBrokerData(this.srcMQAdminExt, topic, srcCluster);
                    Set<String> brokerNameSet = new HashSet<String>();
                    for (BrokerData b : brokerList) {
                        brokerNameSet.add(b.getBrokerName());
                    }
                    TopicRouteData topicRouteData = srcMQAdminExt.examineTopicRouteInfo(topic);
                    if (!topicRouteMap.containsKey(topic)) {
                        topicRouteMap.put(topic, new HashSet<>(16));
                    }
                    for (QueueData qd : topicRouteData.getQueueDatas()) {
                        if (brokerNameSet.contains(qd.getBrokerName())) {
                            for (int i = 0; i < qd.getReadQueueNums(); i++) {
                                TaskTopicInfo taskTopicInfo = new TaskTopicInfo(topic, qd.getBrokerName(), i, targetTopic);
                                topicRouteMap.get(topic).add(taskTopicInfo);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("Fetch topic list error.", e);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) TaskTopicInfo(org.apache.rocketmq.replicator.config.TaskTopicInfo) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) HashSet(java.util.HashSet)

Aggregations

BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)106 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)65 HashMap (java.util.HashMap)41 ArrayList (java.util.ArrayList)29 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)29 HashSet (java.util.HashSet)27 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)23 Map (java.util.Map)22 MQClientException (org.apache.rocketmq.client.exception.MQClientException)21 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)21 List (java.util.List)20 Set (java.util.Set)20 Field (java.lang.reflect.Field)18 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)16 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)16 Entry (java.util.Map.Entry)14 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)14 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)14 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)14