codelipenghui commented on a change in pull request #6362: [ClientAPI]Fix
hasMessageAvailable()
URL: https://github.com/apache/pulsar/pull/6362#discussion_r381346591
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
##########
@@ -1412,6 +1424,51 @@ protected void
handleGetLastMessageId(CommandGetLastMessageId getLastMessageId)
}
}
+ private int getLargestBatchIndex(Topic topic, PositionImpl position, long
requestId) {
+ PersistentTopic persistentTopic = (PersistentTopic) topic;
+ ManagedLedgerImpl ml = (ManagedLedgerImpl)
persistentTopic.getManagedLedger();
+
+ CompletableFuture<Entry> entryFuture = new CompletableFuture<>();
+ ml.asyncReadEntry(position, new AsyncCallbacks.ReadEntryCallback() {
+ @Override
+ public void readEntryComplete(Entry entry, Object ctx) {
+ entryFuture.complete(entry);
+ }
+
+ @Override
+ public void readEntryFailed(ManagedLedgerException exception,
Object ctx) {
+ entryFuture.completeExceptionally(exception);
+ }
+ }, null);
+
+ CompletableFuture<Integer> batchSizeFuture =
entryFuture.thenApply(entry -> {
+ int[] sizeHolder = new int[1];
+ try {
+ MessageParser.parseMessage(TopicName.get(topic.getName()),
entry.getLedgerId(), entry.getEntryId(),
+ entry.getDataBuffer(), (message) -> {
+ sizeHolder[0] = ((RawMessageImpl)
message).getBatchSize();
+ message.release();
+ }, Commands.DEFAULT_MAX_MESSAGE_SIZE);
Review comment:
I think you can use`Commands.parseMessageMetadata(entry.getDataBuffer())` to
get the `MessageMetadata`. The batch size maintained in `MessageMetadata`.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services