Search in sources :

Example 41 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData 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 42 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData 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 43 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData 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 44 with TopicRouteData

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

the class OffsetSyncStore method sync.

private boolean sync(Duration pullTimeout) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData route = adminExt.examineTopicRouteInfo(taskConfig.getOffsetSyncTopic());
    String brokerName = route.getQueueDatas().get(0).getBrokerName();
    MessageQueue mq = new MessageQueue(taskConfig.getOffsetSyncTopic(), brokerName, 0);
    PullResult pr = consumer.pull(mq, "", lastOffset, 0, pullTimeout.getNano() / Duration.ofMillis(1).getNano());
    if (pr.getPullStatus() != PullStatus.FOUND) {
        return false;
    }
    handle(pr);
    return true;
}
Also used : MessageQueue(org.apache.rocketmq.common.message.MessageQueue) PullResult(org.apache.rocketmq.client.consumer.PullResult) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 45 with TopicRouteData

use of org.apache.rocketmq.common.protocol.route.TopicRouteData 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

TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)92 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)65 ArrayList (java.util.ArrayList)25 MQClientException (org.apache.rocketmq.client.exception.MQClientException)25 QueueData (org.apache.rocketmq.common.protocol.route.QueueData)25 HashMap (java.util.HashMap)22 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)20 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)18 List (java.util.List)16 HashSet (java.util.HashSet)13 Entry (java.util.Map.Entry)12 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)12 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)11 Field (java.lang.reflect.Field)10 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)10 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)10 MQClientInstance (org.apache.rocketmq.client.impl.factory.MQClientInstance)10 DefaultMQAdminExtImpl (org.apache.rocketmq.tools.admin.DefaultMQAdminExtImpl)10