You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2021/05/25 02:17:27 UTC
[GitHub] [rocketmq] yuz10 commented on a change in pull request #2943: [ISSUE #2735] QueryMsgByUniqueKey tool should return all messages with same unique key
yuz10 commented on a change in pull request #2943:
URL: https://github.com/apache/rocketmq/pull/2943#discussion_r638399550
##########
File path: tools/src/main/java/org/apache/rocketmq/tools/command/message/QueryMsgByUniqueKeySubCommand.java
##########
@@ -57,82 +58,40 @@ private DefaultMQAdminExt createMQAdminExt(RPCHook rpcHook) throws SubCommandExc
}
}
- 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
- );
+ public static void queryById(final DefaultMQAdminExt admin, final String topic, final String msgId,
+ final boolean showAll) throws MQClientException,
+ RemotingException, MQBrokerException, InterruptedException, IOException {
+
+ QueryResult queryResult = admin.queryMessageByUniqueKey(topic, msgId, 32, 0, Long.MAX_VALUE);
+ assert queryResult != null;
+ List<MessageExt> list = queryResult.getMessageList();
+ list.sort((o1, o2) -> (int) (o1.getStoreTimestamp() - o2.getStoreTimestamp()));
+ for (int i = 0; i < (showAll ? list.size() : 1); i++) {
Review comment:
if list is empty, and showAll is false, `list.get(i)` will throw exeption
##########
File path: tools/src/main/java/org/apache/rocketmq/tools/admin/DefaultMQAdminExt.java
##########
@@ -128,12 +128,18 @@ public MessageExt viewMessage(
}
@Override
- public QueryResult queryMessage(String topic, String key, int maxNum, long begin,
- long end) throws MQClientException,
- InterruptedException {
+ public QueryResult queryMessage(String topic, String key, int maxNum, long begin, long end)
+ throws MQClientException, InterruptedException {
+
return defaultMQAdminExtImpl.queryMessage(topic, key, maxNum, begin, end);
}
+ public QueryResult queryMessageByUniqueKey(String topic, String key, int maxNum, long begin, long end)
Review comment:
The function name, queryMessageByUniqueKey is inconsistent with queryMessageByUniqKey, I suggest keep the same
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org