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_r194108495
 
 

 ##########
 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()) {
+            callback(ResultOk, true);
+        } else {
+            callback(ResultOk, false);
+        }
+    };
+
+    getLastMessageIdAsync(callback1);
+}
+
+void ConsumerImpl::brokerGetLastMessageIdListener(Result res, MessageId 
messageId,
+                                                  
BrokerGetLastMessageIdCallback callback) {
+    if (!callback.empty()) {
+        lastMessageInBroker_ = Optional<MessageId>::of(messageId);
 
 Review comment:
   what happens if there's two calls to getLastMessageId interleaved like:
   
   - call 1 to server
   - response 1 from server
   - call 2 to server
   - response 2 from server with higher message id
   - response 2 reaches client
   - response 1 reaches client
   
   The lastMessageInBroker_ in the client will go backwards. You need some sort 
of atomic check.

----------------------------------------------------------------
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

Reply via email to