sijie commented on a change in pull request #6331: [Issue 2912][pulsar-admin] add get-message-by-id cmd into pulsar-admin URL: https://github.com/apache/pulsar/pull/6331#discussion_r380011558
########## File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java ########## @@ -1403,21 +1404,51 @@ protected void internalResetCursorOnPosition(String subName, boolean authoritati } } - protected Response internalPeekNthMessage(String subName, int messagePosition, boolean authoritative) { - if (topicName.isGlobal()) { - validateGlobalNamespaceOwnership(namespaceName); - } - PartitionedTopicMetadata partitionMetadata = getPartitionedTopicMetadata(topicName, authoritative, false); - if (partitionMetadata.partitions > 0) { - throw new RestException(Status.METHOD_NOT_ALLOWED, "Peek messages on a partitioned topic is not allowed"); + protected Response internalGetMessageById(long ledgerId, long entryId, boolean authoritative) { + verifyReadOperation(authoritative); + + PersistentTopic topic = (PersistentTopic) getTopicReference(topicName); + ManagedLedgerImpl ledger = (ManagedLedgerImpl) topic.getManagedLedger(); + Entry entry = null; + try { + CompletableFuture<Entry> future = new CompletableFuture<>(); + ledger.asyncReadEntry(new PositionImpl(ledgerId, entryId), new AsyncCallbacks.ReadEntryCallback() { + @Override + public void readEntryFailed(ManagedLedgerException exception, Object ctx) { + future.completeExceptionally(exception); + } + + @Override + public void readEntryComplete(Entry entry, Object ctx) { + future.complete(entry); + } + }, null); + + entry = future.get(1000, TimeUnit.MILLISECONDS); Review comment: Sorry for being late in reviewing this pull request. I would suggest implementing this using AsyncResponse. We have tried to move away from using sync methods. You can check `internalCreateSubscription` on how to use AsyncResponse. https://github.com/apache/pulsar/blob/df152109415f2b10dd83e8afe50d9db7ab7cbad5/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/impl/PersistentTopicsBase.java#L1305 ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services