Java Code Examples for com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#queryMessage()

The following examples show how to use com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#queryMessage() . 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: QueryMsgByKeySubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key)
        throws MQClientException, InterruptedException {
    admin.start();

    QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE);
    System.out.printf("%-50s %4s %40s\n",//
        "#Message ID",//
        "#QID",//
        "#Offset");
    for (MessageExt msg : queryResult.getMessageList()) {
        System.out.printf("%-50s %4d %40d\n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset());
    }
}
 
Example 2
Source File: QueryMsgByKeySubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key)
        throws MQClientException, InterruptedException {
    admin.start();

    QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE);
    System.out.printf("%-50s %4s %40s%n",//
            "#Message ID",//
            "#QID",//
            "#Offset");
    for (MessageExt msg : queryResult.getMessageList()) {
        System.out.printf("%-50s %4d %40d%n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset());
    }
}
 
Example 3
Source File: QueryMsgByKeySubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
void queryByKey(final DefaultMQAdminExt admin, final String topic, final String key)
        throws MQClientException, InterruptedException {
    admin.start();

    QueryResult queryResult = admin.queryMessage(topic, key, 64, 0, Long.MAX_VALUE);
    System.out.printf("%-50s %4s %40s\n", //
        "#Message ID", //
        "#QID", //
        "#Offset");
    for (MessageExt msg : queryResult.getMessageList()) {
        System.out.printf("%-50s %4d %40d\n", msg.getMsgId(), msg.getQueueId(), msg.getQueueOffset());
    }
}
 
Example 4
Source File: MessageService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@CmdTrace(cmdClazz = QueryMsgByKeySubCommand.class)
public Table queryMsgByKey(String topicName, String msgKey, String fallbackHours) throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();
    try {
        defaultMQAdminExt.start();
        long h = 0;
        if (StringUtils.isNotBlank(fallbackHours)) {
            h = Long.parseLong(fallbackHours);
        }
        long end = System.currentTimeMillis() - (h * 60 * 60 * 1000);
        long begin = end - (6 * 60 * 60 * 1000);
        QueryResult queryResult = defaultMQAdminExt.queryMessage(topicName, msgKey, 32, begin, end);

        // System.out.printf("%-50s %-4s  %s\n",//
        // "#Message ID",//
        // "#QID",//
        // "#Offset");
        String[] thead = new String[] { "#Message ID", "#QID", "#Offset" };
        int row = queryResult.getMessageList().size();
        Table table = new Table(thead, row);

        for (MessageExt msg : queryResult.getMessageList()) {
            String[] data =
                    new String[] { msg.getMsgId(), String.valueOf(msg.getQueueId()),
                                  String.valueOf(msg.getQueueOffset()) };
            table.insertTR(data);
            // System.out.printf("%-50s %-4d %d\n", msg.getMsgId(),
            // msg.getQueueId(), msg.getQueueOffset());
        }
        return table;
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);
    }
    throw t;
}