|
18 | 18 | */ |
19 | 19 | #include "ConsumerImpl.h" |
20 | 20 |
|
| 21 | +#include <pulsar/MessageIdBuilder.h> |
| 22 | + |
21 | 23 | #include <algorithm> |
22 | 24 |
|
23 | 25 | #include "AckGroupingTracker.h" |
@@ -471,8 +473,7 @@ void ConsumerImpl::messageReceived(const ClientConnectionPtr& cnx, const proto:: |
471 | 473 | // Only a non-batched messages can be a chunk |
472 | 474 | if (!metadata.has_num_messages_in_batch() && isChunkedMessage) { |
473 | 475 | const auto& messageIdData = msg.message_id(); |
474 | | - MessageId messageId(messageIdData.partition(), messageIdData.ledgerid(), messageIdData.entryid(), |
475 | | - messageIdData.batch_index()); |
| 476 | + auto messageId = MessageIdBuilder::from(messageIdData).build(); |
476 | 477 | auto optionalPayload = processMessageChunk(payload, metadata, messageId, messageIdData, cnx); |
477 | 478 | if (optionalPayload.is_present()) { |
478 | 479 | payload = optionalPayload.value(); |
@@ -629,7 +630,7 @@ uint32_t ConsumerImpl::receiveIndividualMessagesFromBatch(const ClientConnection |
629 | 630 |
|
630 | 631 | for (int i = 0; i < batchSize; i++) { |
631 | 632 | // This is a cheap copy since message contains only one shared pointer (impl_) |
632 | | - Message msg = Commands::deSerializeSingleMessageInBatch(batchedMessage, i); |
| 633 | + Message msg = Commands::deSerializeSingleMessageInBatch(batchedMessage, i, batchSize); |
633 | 634 | msg.impl_->setRedeliveryCount(redeliveryCount); |
634 | 635 | msg.impl_->setTopicName(batchedMessage.getTopicName()); |
635 | 636 | msg.impl_->convertPayloadToKeyValue(config_.getSchema()); |
@@ -929,13 +930,17 @@ Optional<MessageId> ConsumerImpl::clearReceiveQueue() { |
929 | 930 | if (incomingMessages_.peekAndClear(nextMessageInQueue)) { |
930 | 931 | // There was at least one message pending in the queue |
931 | 932 | const MessageId& nextMessageId = nextMessageInQueue.getMessageId(); |
932 | | - MessageId previousMessageId; |
933 | | - if (nextMessageId.batchIndex() >= 0) { |
934 | | - previousMessageId = MessageId(-1, nextMessageId.ledgerId(), nextMessageId.entryId(), |
935 | | - nextMessageId.batchIndex() - 1); |
936 | | - } else { |
937 | | - previousMessageId = MessageId(-1, nextMessageId.ledgerId(), nextMessageId.entryId() - 1, -1); |
938 | | - } |
| 933 | + auto previousMessageId = (nextMessageId.batchIndex() >= 0) |
| 934 | + ? MessageIdBuilder() |
| 935 | + .ledgerId(nextMessageId.ledgerId()) |
| 936 | + .entryId(nextMessageId.entryId()) |
| 937 | + .batchIndex(nextMessageId.batchIndex() - 1) |
| 938 | + .batchSize(nextMessageId.batchSize()) |
| 939 | + .build() |
| 940 | + : MessageIdBuilder() |
| 941 | + .ledgerId(nextMessageId.ledgerId()) |
| 942 | + .entryId(nextMessageId.entryId() - 1) |
| 943 | + .build(); |
939 | 944 | return Optional<MessageId>::of(previousMessageId); |
940 | 945 | } else if (lastDequedMessageId_ != MessageId::earliest()) { |
941 | 946 | // If the queue was empty we need to restart from the message just after the last one that has been |
|
0 commit comments