Skip to content

Commit 03a2f4a

Browse files
committed
Make ConsumerRecord to be copyable
1 parent 82cbd27 commit 03a2f4a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/kafka/ConsumerRecord.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class ConsumerRecord
8787
std::string toString() const;
8888

8989
private:
90-
using rd_kafka_message_unique_ptr = std::unique_ptr<rd_kafka_message_t, void(*)(rd_kafka_message_t*)>;
91-
rd_kafka_message_unique_ptr _rk_msg;
90+
using rd_kafka_message_shared_ptr = std::shared_ptr<rd_kafka_message_t>;
91+
rd_kafka_message_shared_ptr _rk_msg;
9292
};
9393

9494
inline Headers

include/kafka/ProducerRecord.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ namespace KAFKA_API::clients::producer {
1313
/**
1414
* A key/value pair to be sent to Kafka.
1515
* This consists of a topic name to which the record is being sent, an optional partition number, and an optional key and value.
16+
* Note: `ProducerRecord` would not take the ownership from the memory block of `Value`.
1617
*/
1718
class ProducerRecord
1819
{
1920
public:
2021
using Id = std::uint64_t;
2122

22-
// Note: ProducerRecord would not take the ownership from these parameters,
2323
ProducerRecord(Topic topic, Partition partition, const Key& key, const Value& value)
2424
: _topic(std::move(topic)), _partition(partition), _key(key), _value(value) {}
2525

tests/integration/TestKafkaConsumer.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ TEST(KafkaConsumer, BasicPoll)
6060
records = KafkaTestUtility::ConsumeMessagesUntilTimeout(consumer);
6161
EXPECT_EQ(messages.size(), records.size());
6262

63+
// Copyable ConsumerRecord
64+
{
65+
auto recordsCopy = records;
66+
recordsCopy.clear();
67+
}
68+
6369
// Check messages
6470
std::size_t rcvMsgCount = 0;
6571
for (auto& record: records)

0 commit comments

Comments
 (0)