From c34796bd06321560c88deab8bfa7a1ab560ddeb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9C=E9=98=B3?= Date: Tue, 25 May 2021 21:10:41 +0800 Subject: [PATCH] [ISSUE #2735] QueryMsgByUniqueKey tool should return all messages with same unique key --- .../org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java | 2 +- .../tools/command/message/QueryMsgByUniqueKeySubCommand.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java index cab36e7d..af2bd715 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java @@ -134,7 +134,7 @@ public class DefaultMQAdminExt extends ClientConfig implements MQAdminExt { return defaultMQAdminExtImpl.queryMessage(topic, key, maxNum, begin, end); } - public QueryResult queryMessageByUniqueKey(String topic, String key, int maxNum, long begin, long end) + public QueryResult queryMessageByUniqKey(String topic, String key, int maxNum, long begin, long end) throws MQClientException, InterruptedException { return defaultMQAdminExtImpl.queryMessageByUniqKey(topic, key, maxNum, begin, end); diff --git a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java index badac114..8c7bec61 100644 --- a/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java +++ b/tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java @@ -62,9 +62,12 @@ public class QueryMsgByUniqueKeySubCommand implements SubCommand { final boolean showAll) throws MQClientException, RemotingException, MQBrokerException, InterruptedException, IOException { - QueryResult queryResult = admin.queryMessageByUniqueKey(topic, msgId, 32, 0, Long.MAX_VALUE); + QueryResult queryResult = admin.queryMessageByUniqKey(topic, msgId, 32, 0, Long.MAX_VALUE); assert queryResult != null; List list = queryResult.getMessageList(); + if (list == null || list.size() == 0) { + return; + } list.sort((o1, o2) -> (int) (o1.getStoreTimestamp() - o2.getStoreTimestamp())); for (int i = 0; i < (showAll ? list.size() : 1); i++) { showMessage(admin, list.get(i), i); -- GitLab