Java Code Examples for org.apache.rocketmq.common.protocol.route.TopicRouteData#getQueueDatas()

The following examples show how to use org.apache.rocketmq.common.protocol.route.TopicRouteData#getQueueDatas() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public Message queryLatestMessage(String nameServer, String topic) throws Exception {
    DefaultMQAdminExt defaultMQAdminExt = getMQAdminExt(nameServer);

    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
    if (topicRouteData == null) {
        throw new MqException("[RMQ] topic<" + topic + "> route info is null");
    }

    List<QueueData> queueDatas = topicRouteData.getQueueDatas();
    Collections.shuffle(queueDatas);
    for (QueueData queueData : queueDatas) {
        for (int i = 0; i < queueData.getReadQueueNums(); i++) {
            long maxOffsets = defaultMQAdminExt.maxOffset(new MessageQueue(topic, queueData.getBrokerName(), i));
            if (maxOffsets <= 0) {
                continue;
            }
            Message msg = queryMessageByOffset(nameServer, topic, queueData.getBrokerName(), i, maxOffsets - 1);
            if (msg != null) {
                return msg;
            }
        }
    }

    throw new MqException("[RMQ] fetch rmq latestmsg error, not exist");
}
 
Example 2
Source File: DefaultMQAdminExtImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testResetOffset() throws Exception {

    TopicRouteData routeInfo = mqAdmin.examineTopicRouteInfo(topic);
    System.out.println();
    for (BrokerData brokerData : routeInfo.getBrokerDatas()) {
        System.out.println(brokerData);
    }
    System.out.println();
    for (QueueData data : routeInfo.getQueueDatas()) {
        MessageQueue mq = new MessageQueue(topic, data.getBrokerName(), 0);
        long offset = mqAdmin.searchOffset(mq, System.currentTimeMillis());
        System.out.println(data + ", offset:" + offset);
    }
    System.out.println();
    List<RollbackStats> r = mqAdmin.resetOffsetByTimestampOld(group, topic, System.currentTimeMillis(), true);
    for (RollbackStats rollbackStats : r) {
        System.out.println(rollbackStats);
    }

}
 
Example 3
Source File: RmqAdminServiceImpl.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Override
public Message queryLatestMessage(String nameServer, String topic) throws Exception {
    DefaultMQAdminExt defaultMQAdminExt = getMQAdminExt(nameServer);

    TopicRouteData topicRouteData = defaultMQAdminExt.examineTopicRouteInfo(topic);
    if (topicRouteData == null) {
        throw new MqException("[RMQ] topic<" + topic + "> route info is null");
    }

    List<QueueData> queueDatas = topicRouteData.getQueueDatas();
    Collections.shuffle(queueDatas);
    for (QueueData queueData : queueDatas) {
        for (int i = 0; i < queueData.getReadQueueNums(); i++) {
            long maxOffsets = defaultMQAdminExt.maxOffset(new MessageQueue(topic, queueData.getBrokerName(), i));
            if (maxOffsets <= 0) {
                continue;
            }
            Message msg = queryMessageByOffset(nameServer, topic, queueData.getBrokerName(), i, maxOffsets - 1);
            if (msg != null) {
                return msg;
            }
        }
    }

    throw new MqException("[RMQ] fetch rmq latestmsg error, not exist");
}
 
Example 4
Source File: DefaultMQAdminExtImplTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testResetOffset() throws Exception {

    TopicRouteData routeInfo = mqAdmin.examineTopicRouteInfo(topic);
    System.out.println();
    for (BrokerData brokerData : routeInfo.getBrokerDatas()) {
        System.out.println(brokerData);
    }
    System.out.println();
    for (QueueData data : routeInfo.getQueueDatas()) {
        MessageQueue mq = new MessageQueue(topic, data.getBrokerName(), 0);
        long offset = mqAdmin.searchOffset(mq, System.currentTimeMillis());
        System.out.println(data + ", offset:" + offset);
    }
    System.out.println();
    List<RollbackStats> r = mqAdmin.resetOffsetByTimestampOld(group, topic, System.currentTimeMillis(), true);
    for (RollbackStats rollbackStats : r) {
        System.out.println(rollbackStats);
    }

}
 
Example 5
Source File: Utils.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static boolean isBrokerTopicWritable(String cluster, String nameSvr, String address/* broker Address */) {

        try {
            DefaultMQAdminExt adminExt = getMQAdminExt(nameSvr, cluster);
            String brokerPermission = adminExt.getBrokerConfig(address).getProperty("brokerPermission");
            if (!PermName.isWriteable(Integer.parseInt(brokerPermission))) {
                logger.info("skip send because of broker brokerPermission={}. cluster={}, namesvr={}, address={}",
                        brokerPermission, cluster, nameSvr, address);
                return false;
            }
            TopicRouteData topicRouteInfo = adminExt.examineTopicRouteInfo("SELF_TEST_TOPIC");

            String brokerName = null;
            for (BrokerData brokerData : topicRouteInfo.getBrokerDatas()) {
                if (StringUtils.equals(brokerData.getBrokerAddrs().get(0L), address)) {
                    brokerName = brokerData.getBrokerName();
                    break;
                }
            }
            if (brokerName != null) {
                for (QueueData queueData : topicRouteInfo.getQueueDatas()) {
                    if (StringUtils.equals(queueData.getBrokerName(), brokerName)) {
                        if (queueData.getWriteQueueNums() == 0 || !PermName.isWriteable(queueData.getPerm())) {
                            logger.info("skip send because of queue.Permission={},queue.writeQNuum={}. cluster={}, namesvr={}, address={}",
                                    queueData.getPerm(), queueData.getWriteQueueNums(), cluster, nameSvr, address);
                            return false;
                        }
                        break;
                    }
                }
            }
        } catch (Exception e) {
            logger.error("exception in isBrokerTopicWritable, cluster={}, namesvr={}, address={}", cluster, nameSvr, address, e);
        }
        return true;
    }
 
Example 6
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 7
Source File: MQClientInstance.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 8
Source File: MQClientInstance.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
/**
 * topicRoute转化成TopicSubscribeInfo
 * @param topic ;
 * @param route ;
 * @return ;
 */
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 9
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
/**
 * 提取TopicRouteData内的QueueData生成MessageQueue,也就是Topic的订阅队列信息
 *
 * @param topic
 * @param route
 * @return
 */
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    Set<MessageQueue> mqList = new HashSet<>();
    List<QueueData> qds = route.getQueueDatas();
    for (QueueData qd : qds) {
        if (PermName.isReadable(qd.getPerm())) {  // QueueData是否可读, %DLQ%+consumeGroup 队列只能写不能读
            for (int i = 0; i < qd.getReadQueueNums(); i++) {
                MessageQueue mq = new MessageQueue(topic, qd.getBrokerName(), i);
                mqList.add(mq);
            }
        }
    }
    return mqList;
}
 
Example 10
Source File: Utils.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static boolean isBrokerTopicWritable(String cluster, String nameSvr, String address/* broker Address */) {

        try {
            DefaultMQAdminExt adminExt = getMQAdminExt(nameSvr, cluster);
            String brokerPermission = adminExt.getBrokerConfig(address).getProperty("brokerPermission");
            if (!PermName.isWriteable(Integer.parseInt(brokerPermission))) {
                logger.info("skip send because of broker brokerPermission={}. cluster={}, namesvr={}, address={}",
                        brokerPermission, cluster, nameSvr, address);
                return false;
            }
            TopicRouteData topicRouteInfo = adminExt.examineTopicRouteInfo("SELF_TEST_TOPIC");

            String brokerName = null;
            for (BrokerData brokerData : topicRouteInfo.getBrokerDatas()) {
                if (StringUtils.equals(brokerData.getBrokerAddrs().get(0L), address)) {
                    brokerName = brokerData.getBrokerName();
                    break;
                }
            }
            if (brokerName != null) {
                for (QueueData queueData : topicRouteInfo.getQueueDatas()) {
                    if (StringUtils.equals(queueData.getBrokerName(), brokerName)) {
                        if (queueData.getWriteQueueNums() == 0 || !PermName.isWriteable(queueData.getPerm())) {
                            logger.info("skip send because of queue.Permission={},queue.writeQNuum={}. cluster={}, namesvr={}, address={}",
                                    queueData.getPerm(), queueData.getWriteQueueNums(), cluster, nameSvr, address);
                            return false;
                        }
                        break;
                    }
                }
            }
        } catch (Exception e) {
            logger.error("exception in isBrokerTopicWritable, cluster={}, namesvr={}, address={}", cluster, nameSvr, address, e);
        }
        return true;
    }
 
Example 11
Source File: MQClientInstance.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 12
Source File: MQClientInstance.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 13
Source File: MQClientInstance.java    From rocketmq_trans_message with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}
 
Example 14
Source File: MQClientInstance.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public static Set<MessageQueue> topicRouteData2TopicSubscribeInfo(final String topic, final TopicRouteData route) {
    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);
            }
        }
    }

    return mqList;
}