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

The following examples show how to use com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#viewMessage() . 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: QueryMsgByIdSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public static void queryById(final DefaultMQAdminExt admin, final String msgId) throws MQClientException,
        RemotingException, MQBrokerException, InterruptedException, IOException {
    MessageExt msg = admin.viewMessage(msgId);

    String bodyTmpFilePath = createBodyFile(msg);

    System.out.printf("%-20s %s\n",//
        "Topic:",//
        msg.getTopic()//
        );

    System.out.printf("%-20s %s\n",//
        "Tags:",//
        "[" + msg.getTags() + "]"//
    );

    System.out.printf("%-20s %s\n",//
        "Keys:",//
        "[" + msg.getKeys() + "]"//
    );

    System.out.printf("%-20s %d\n",//
        "Queue ID:",//
        msg.getQueueId()//
        );

    System.out.printf("%-20s %d\n",//
        "Queue Offset:",//
        msg.getQueueOffset()//
        );

    System.out.printf("%-20s %d\n",//
        "CommitLog Offset:",//
        msg.getCommitLogOffset()//
        );

    System.out.printf("%-20s %d\n",//
        "Reconsume Times:",//
        msg.getReconsumeTimes()//
        );

    System.out.printf("%-20s %s\n",//
        "Born Timestamp:",//
        UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())//
        );

    System.out.printf("%-20s %s\n",//
        "Store Timestamp:",//
        UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())//
        );

    System.out.printf("%-20s %s\n",//
        "Born Host:",//
        RemotingHelper.parseSocketAddressAddr(msg.getBornHost())//
        );

    System.out.printf("%-20s %s\n",//
        "Store Host:",//
        RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())//
        );

    System.out.printf("%-20s %d\n",//
        "System Flag:",//
        msg.getSysFlag()//
        );

    System.out.printf("%-20s %s\n",//
        "Properties:",//
        msg.getProperties() != null ? msg.getProperties().toString() : ""//
    );

    System.out.printf("%-20s %s\n",//
        "Message Body Path:",//
        bodyTmpFilePath//
        );

    try {
        List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
        if (mtdList.isEmpty()) {
            System.out.println("\n\nWARN: No Consumer");
        }
        else {
            System.out.println("\n\n");
            for (MessageTrack mt : mtdList) {
                System.out.println(mt);
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: MessageService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@CmdTrace(cmdClazz = QueryMsgByIdSubCommand.class)
public Table queryMsgById(String msgId) throws Throwable {
    Throwable t = null;
    Map<String, String> map = new LinkedHashMap<String, String>();
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();
    try {
        defaultMQAdminExt.start();
        MessageExt msg = defaultMQAdminExt.viewMessage(msgId);
        String bodyTmpFilePath = createBodyFile(msg);
        // System.out.printf("%-20s %s\n",//
        // "Topic:",//
        // msg.getTopic()//
        // );
        map.put("Topic", msg.getTopic());

        // System.out.printf("%-20s %s\n",//
        // "Tags:",//
        // "[" + msg.getTags() + "]"//
        // );
        map.put("Tags", "[" + msg.getTags() + "]");

        // System.out.printf("%-20s %s\n",//
        // "Keys:",//
        // "[" + msg.getKeys() + "]"//
        // );
        map.put("Keys", "[" + msg.getKeys() + "]");

        // System.out.printf("%-20s %d\n",//
        // "Queue ID:",//
        // msg.getQueueId()//
        // );
        map.put("Queue ID", String.valueOf(msg.getQueueId()));

        // System.out.printf("%-20s %d\n",//
        // "Queue Offset:",//
        // msg.getQueueOffset()//
        // );
        map.put("Queue Offset:", String.valueOf(msg.getQueueOffset()));

        // System.out.printf("%-20s %d\n",//
        // "CommitLog Offset:",//
        // msg.getCommitLogOffset()//
        // );
        map.put("CommitLog Offset:", String.valueOf(msg.getCommitLogOffset()));

        // System.out.printf("%-20s %s\n",//
        // "Born Timestamp:",//
        // UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())//
        // );
        map.put("Born Timestamp:", UtilAll.timeMillisToHumanString2(msg.getBornTimestamp()));

        // System.out.printf("%-20s %s\n",//
        // "Store Timestamp:",//
        // UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())//
        // );
        map.put("Store Timestamp:", UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp()));

        // System.out.printf("%-20s %s\n",//
        // "Born Host:",//
        // RemotingHelper.parseSocketAddressAddr(msg.getBornHost())//
        // );
        map.put("Born Host:", RemotingHelper.parseSocketAddressAddr(msg.getBornHost()));

        // System.out.printf("%-20s %s\n",//
        // "Store Host:",//
        // RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())//
        // );
        map.put("Store Host:", RemotingHelper.parseSocketAddressAddr(msg.getStoreHost()));

        // System.out.printf("%-20s %d\n",//
        // "System Flag:",//
        // msg.getSysFlag()//
        // );
        map.put("System Flag:", String.valueOf(msg.getSysFlag()));

        // System.out.printf("%-20s %s\n",//
        // "Properties:",//
        // msg.getProperties() != null ? msg.getProperties().toString() :
        // ""//
        // );
        map.put("Properties:", msg.getProperties() != null ? msg.getProperties().toString() : "");

        // System.out.printf("%-20s %s\n",//
        // "Message Body Path:",//
        // bodyTmpFilePath//
        // );
        map.put("Message Body Path:", bodyTmpFilePath);
        return Table.Map2VTable(map);
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);

    }
    throw t;
}
 
Example 3
Source File: QueryMsgByIdSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public static void queryById(final DefaultMQAdminExt admin, final String msgId) throws MQClientException,
        RemotingException, MQBrokerException, InterruptedException, IOException {
    MessageExt msg = admin.viewMessage(msgId);


    String bodyTmpFilePath = createBodyFile(msg);

    System.out.printf("%-20s %s%n",//
            "Topic:",//
            msg.getTopic()//
    );

    System.out.printf("%-20s %s%n",//
            "Tags:",//
            "[" + msg.getTags() + "]"//
    );

    System.out.printf("%-20s %s%n",//
            "Keys:",//
            "[" + msg.getKeys() + "]"//
    );

    System.out.printf("%-20s %d%n",//
            "Queue ID:",//
            msg.getQueueId()//
    );

    System.out.printf("%-20s %d%n",//
            "Queue Offset:",//
            msg.getQueueOffset()//
    );

    System.out.printf("%-20s %d%n",//
            "CommitLog Offset:",//
            msg.getCommitLogOffset()//
    );

    System.out.printf("%-20s %d%n",//
            "Reconsume Times:",//
            msg.getReconsumeTimes()//
    );

    System.out.printf("%-20s %s%n",//
            "Born Timestamp:",//
            UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())//
    );

    System.out.printf("%-20s %s%n",//
            "Store Timestamp:",//
            UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())//
    );

    System.out.printf("%-20s %s%n",//
            "Born Host:",//
            RemotingHelper.parseSocketAddressAddr(msg.getBornHost())//
    );

    System.out.printf("%-20s %s%n",//
            "Store Host:",//
            RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())//
    );

    System.out.printf("%-20s %d%n",//
            "System Flag:",//
            msg.getSysFlag()//
    );

    System.out.printf("%-20s %s%n",//
            "Properties:",//
            msg.getProperties() != null ? msg.getProperties().toString() : ""//
    );

    System.out.printf("%-20s %s%n",//
            "Message Body Path:",//
            bodyTmpFilePath//
    );

    try {
        List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
        if (mtdList.isEmpty()) {
            System.out.println("\n\nWARN: No Consumer");
        } else {
            System.out.println("\n\n");
            for (MessageTrack mt : mtdList) {
                System.out.println(mt);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 4
Source File: QueryMsgByUniqueKeySubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId) throws MQClientException,
        RemotingException, MQBrokerException, InterruptedException, IOException {
    MessageExt msg = admin.viewMessage(topic,msgId);


    String bodyTmpFilePath = createBodyFile(msg);

    System.out.printf("%-20s %s%n",//
        "Topic:",//
        msg.getTopic()//
        );

    System.out.printf("%-20s %s%n",//
        "Tags:",//
        "[" + msg.getTags() + "]"//
    );

    System.out.printf("%-20s %s%n",//
        "Keys:",//
        "[" + msg.getKeys() + "]"//
    );

    System.out.printf("%-20s %d%n",//
        "Queue ID:",//
        msg.getQueueId()//
        );

    System.out.printf("%-20s %d%n",//
        "Queue Offset:",//
        msg.getQueueOffset()//
        );

    System.out.printf("%-20s %d%n",//
        "CommitLog Offset:",//
        msg.getCommitLogOffset()//
        );

    System.out.printf("%-20s %d%n",//
        "Reconsume Times:",//
        msg.getReconsumeTimes()//
        );

    System.out.printf("%-20s %s%n",//
        "Born Timestamp:",//
        UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())//
        );

    System.out.printf("%-20s %s%n",//
        "Store Timestamp:",//
        UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())//
        );

    System.out.printf("%-20s %s%n",//
        "Born Host:",//
        RemotingHelper.parseSocketAddressAddr(msg.getBornHost())//
        );

    System.out.printf("%-20s %s%n",//
        "Store Host:",//
        RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())//
        );

    System.out.printf("%-20s %d%n",//
        "System Flag:",//
        msg.getSysFlag()//
        );

    System.out.printf("%-20s %s%n",//
        "Properties:",//
        msg.getProperties() != null ? msg.getProperties().toString() : ""//
    );

    System.out.printf("%-20s %s%n",//
        "Message Body Path:",//
        bodyTmpFilePath//
        );

    try {
        List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
        if (mtdList.isEmpty()) {
            System.out.println("\n\nWARN: No Consumer");
        }
        else {
            System.out.println("\n\n");
            for (MessageTrack mt : mtdList) {
                System.out.println(mt);
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: QueryMsgByIdSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public static void queryById(final DefaultMQAdminExt admin, final String msgId) throws MQClientException,
        RemotingException, MQBrokerException, InterruptedException, IOException {
    MessageExt msg = admin.viewMessage(msgId);

    // 存储消息 body 到指定路径
    String bodyTmpFilePath = createBodyFile(msg);

    System.out.printf("%-20s %s\n", //
        "Topic:", //
        msg.getTopic()//
    );

    System.out.printf("%-20s %s\n", //
        "Tags:", //
        "[" + msg.getTags() + "]"//
    );

    System.out.printf("%-20s %s\n", //
        "Keys:", //
        "[" + msg.getKeys() + "]"//
    );

    System.out.printf("%-20s %d\n", //
        "Queue ID:", //
        msg.getQueueId()//
    );

    System.out.printf("%-20s %d\n", //
        "Queue Offset:", //
        msg.getQueueOffset()//
    );

    System.out.printf("%-20s %d\n", //
        "CommitLog Offset:", //
        msg.getCommitLogOffset()//
    );

    System.out.printf("%-20s %d\n", //
        "Reconsume Times:", //
        msg.getReconsumeTimes()//
    );

    System.out.printf("%-20s %s\n", //
        "Born Timestamp:", //
        UtilAll.timeMillisToHumanString2(msg.getBornTimestamp())//
    );

    System.out.printf("%-20s %s\n", //
        "Store Timestamp:", //
        UtilAll.timeMillisToHumanString2(msg.getStoreTimestamp())//
    );

    System.out.printf("%-20s %s\n", //
        "Born Host:", //
        RemotingHelper.parseSocketAddressAddr(msg.getBornHost())//
    );

    System.out.printf("%-20s %s\n", //
        "Store Host:", //
        RemotingHelper.parseSocketAddressAddr(msg.getStoreHost())//
    );

    System.out.printf("%-20s %d\n", //
        "System Flag:", //
        msg.getSysFlag()//
    );

    System.out.printf("%-20s %s\n", //
        "Properties:", //
        msg.getProperties() != null ? msg.getProperties().toString() : ""//
    );

    System.out.printf("%-20s %s\n", //
        "Message Body Path:", //
        bodyTmpFilePath//
    );

    try {
        List<MessageTrack> mtdList = admin.messageTrackDetail(msg);
        if (mtdList.isEmpty()) {
            System.out.println("\n\nWARN: No Consumer");
        }
        else {
            System.out.println("\n\n");
            for (MessageTrack mt : mtdList) {
                System.out.println(mt);
            }
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}