ivankelly commented on a change in pull request #1861: Cpp client: add
getLastMessageId and hasMessageAvailable in consmer and reader
URL: https://github.com/apache/incubator-pulsar/pull/1861#discussion_r194106349
##########
File path: pulsar-client-cpp/lib/ConsumerImpl.cc
##########
@@ -919,4 +919,65 @@ void ConsumerImpl::seekAsync(const MessageId& msgId,
ResultCallback callback) {
callback(ResultNotConnected);
}
+void ConsumerImpl::hasMessageAvailableAsync(HasMessageAvailableCallback
callback) {
+ if (this->lastMessageIdAvailable()) {
+ callback(ResultOk, true);
+ return;
+ }
+
+ BrokerGetLastMessageIdCallback callback1 = [this, callback](Result result,
MessageId messageId) {
+ if (this->lastMessageIdAvailable()) {
Review comment:
This is action at a distance which can be a pain to debug when stuff goes
wrong.
Rather than making the assumption about the lastMessageInBroker being
updated in the background, the messageId passed as a parameter should be used.
So lastMessageIdInBroker is only directly used in the short circuit path.
```
void ConsumerImpl::hasMessageAvailableAsync(HasMessageAvailableCallback
callback) {
MessageId lastDequeud = this->lastMessageIdDequed();
if (lastDequeued < this->lastMessageIdInBroker()) {
callback(ResultOk, true);
return;
}
BrokerGetLastMessageIdCallback callback1 = [this, callback](Result
result, MessageId messageId) {
if (result == ResultOk) {
if (messageId > lastDequeued) {
callback(ResultOk, true);
} else {
callback(ResultOk, false);
}
} else {
callback(result, false);
}
};
getLastMessageIdAsync(callback1);
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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