Skip to content

Commit

Permalink
[pulsar-client-cpp] Add MessageId to send Message (apache#7439)
Browse files Browse the repository at this point in the history
* fix: add message id to send message in cpp

* test: fix produce consume test to check whether message id was changed or not
  • Loading branch information
equanz authored Jul 5, 2020
1 parent 35bb235 commit ca783fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pulsar-client-cpp/include/pulsar/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class PULSAR_PUBLIC Message {
*/
const MessageId& getMessageId() const;

/**
* Set the unique message ID.
*
*/
void setMessageId(const MessageId& messageID) const;

/**
* Get the partition key for this message
* @return key string that is hashed to determine message's topic partition
Expand Down
7 changes: 7 additions & 0 deletions pulsar-client-cpp/lib/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ const MessageId& Message::getMessageId() const {
}
}

void Message::setMessageId(const MessageId& messageID) const {
if (impl_) {
impl_->messageId = messageID;
}
return;
}

bool Message::hasPartitionKey() const {
if (impl_) {
return impl_->hasPartitionKey();
Expand Down
2 changes: 2 additions & 0 deletions pulsar-client-cpp/lib/Producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Result Producer::send(const Message& msg) {

MessageId mi;
Result result = promise.getFuture().get(mi);
msg.setMessageId(mi);

return result;
}

Expand Down
2 changes: 2 additions & 0 deletions pulsar-client-cpp/tests/BasicEndToEndTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,10 @@ TEST(BasicEndToEndTest, testProduceConsume) {
// Send synchronously
std::string content = "msg-1-content";
Message msg = MessageBuilder().setContent(content).build();
ASSERT_EQ(MessageId(-1, -1, -1, -1), msg.getMessageId());
result = producer.send(msg);
ASSERT_EQ(ResultOk, result);
ASSERT_NE(MessageId(-1, -1, -1, -1), msg.getMessageId());

Message receivedMsg;
consumer.receive(receivedMsg);
Expand Down

0 comments on commit ca783fc

Please sign in to comment.