Java Code Examples for org.apache.rocketmq.common.protocol.route.QueueData#getReadQueueNums()

The following examples show how to use org.apache.rocketmq.common.protocol.route.QueueData#getReadQueueNums() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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;
}