Skip to content

Commit 28e7b27

Browse files
Jørgen Foghkenneth-jia
authored andcommitted
Subrange in KafkaConsumer::pollMessages()
The `std::for_each` in `KafkaConsumer::pollMessages()` should not copy the whole buffer, only the received messages.
1 parent 7b68ce2 commit 28e7b27

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/kafka/KafkaConsumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ KafkaConsumer::pollMessages(int timeoutMs, std::vector<consumer::ConsumerRecord>
817817
// Wrap messages with ConsumerRecord
818818
output.clear();
819819
output.reserve(msgReceived);
820-
std::for_each(msgPtrArray.begin(), msgPtrArray.end(), [&output](rd_kafka_message_t* rkMsg) { output.emplace_back(rkMsg); });
820+
std::for_each(msgPtrArray.begin(), msgPtrArray.begin() + msgReceived, [&output](rd_kafka_message_t* rkMsg) { output.emplace_back(rkMsg); });
821821

822822
// Store the offsets for all these polled messages (for "enable.auto.commit=true" case)
823823
storeOffsetsIfNecessary(output);

0 commit comments

Comments
 (0)