Search in sources :

Example 91 with TopicRouteData

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

the class DefaultMQAdminExtImpl method getConsumeStatus.

@Override
public Map<String, Map<MessageQueue, Long>> getConsumeStatus(String topic, String group, String clientAddr) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<BrokerData> brokerDatas = topicRouteData.getBrokerDatas();
    if (brokerDatas != null && brokerDatas.size() > 0) {
        String addr = brokerDatas.get(0).selectBrokerAddr();
        if (addr != null) {
            return this.mqClientInstance.getMQClientAPIImpl().invokeBrokerToGetConsumerStatus(addr, topic, group, clientAddr, timeoutMillis);
        }
    }
    return Collections.EMPTY_MAP;
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 92 with TopicRouteData

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

the class DefaultMQAdminExtImpl method resetOffsetByTimestampOld.

@Override
public List<RollbackStats> resetOffsetByTimestampOld(String consumerGroup, String topic, long timestamp, boolean force) throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    List<RollbackStats> rollbackStatsList = new ArrayList<RollbackStats>();
    Map<String, Integer> topicRouteMap = new HashMap<String, Integer>();
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        for (QueueData queueData : topicRouteData.getQueueDatas()) {
            topicRouteMap.put(bd.selectBrokerAddr(), queueData.getReadQueueNums());
        }
    }
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            ConsumeStats consumeStats = this.mqClientInstance.getMQClientAPIImpl().getConsumeStats(addr, consumerGroup, timeoutMillis);
            boolean hasConsumed = false;
            for (Map.Entry<MessageQueue, OffsetWrapper> entry : consumeStats.getOffsetTable().entrySet()) {
                MessageQueue queue = entry.getKey();
                OffsetWrapper offsetWrapper = entry.getValue();
                if (topic.equals(queue.getTopic())) {
                    hasConsumed = true;
                    RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
                    rollbackStatsList.add(rollbackStats);
                }
            }
            if (!hasConsumed) {
                HashMap<MessageQueue, TopicOffset> topicStatus = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis).getOffsetTable();
                for (int i = 0; i < topicRouteMap.get(addr); i++) {
                    MessageQueue queue = new MessageQueue(topic, bd.getBrokerName(), i);
                    OffsetWrapper offsetWrapper = new OffsetWrapper();
                    offsetWrapper.setBrokerOffset(topicStatus.get(queue).getMaxOffset());
                    offsetWrapper.setConsumerOffset(topicStatus.get(queue).getMinOffset());
                    RollbackStats rollbackStats = resetOffsetConsumeOffset(addr, consumerGroup, queue, offsetWrapper, timestamp, force);
                    rollbackStatsList.add(rollbackStats);
                }
            }
        }
    }
    return rollbackStatsList;
}
Also used : HashMap(java.util.HashMap) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) QueueData(org.apache.rocketmq.common.protocol.route.QueueData) ArrayList(java.util.ArrayList) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) RollbackStats(org.apache.rocketmq.common.admin.RollbackStats) Map(java.util.Map) HashMap(java.util.HashMap)

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