BewareMyPower opened a new issue, #16761:
URL: https://github.com/apache/pulsar/issues/16761

   **Describe the bug**
   When C++ client calls `ConsumerImpl::getLastMessageIdAsync`, if the 
connection is not established, the callback will complete with 
`ResultNotConnected`.
   
   **To Reproduce**
   Add the following test to `ReaderTest.cc` and run it.
   
   ```c++
   TEST(ReaderTest, testReceiveAfterSeek) {
       Client client(serviceUrl);
       const std::string topic = "reader-test-receive-after-seek-" + 
std::to_string(time(nullptr));
   
       Producer producer;
       ASSERT_EQ(ResultOk, client.createProducer(topic, producer));
   
       MessageId seekMessageId;
       for (int i = 0; i < 5; i++) {
           MessageId messageId;
           producer.send(MessageBuilder().setContent("msg-" + 
std::to_string(i)).build(), messageId);
           if (i == 3) {
               seekMessageId = messageId;
           }
       }
   
       Reader reader;
       ASSERT_EQ(ResultOk, client.createReader(topic, MessageId::latest(), {}, 
reader));
   
       reader.seek(seekMessageId);
   
       bool hasMessageAvailable;
       // it returns ResultNotConnected because hasMessageAvailable calls 
getLastMessageIdAsync internally
       ASSERT_EQ(ResultOk, reader.hasMessageAvailable(hasMessageAvailable));
   
       client.close();
   }
   ```
   
   **Expected behavior**
   `getLastMessageIdAsync` should wait until the connection is established like 
`ConsumerImpl#internalGetLastMessageIdAsync` in Java client.
   
   Currently, a workaround is to manually wait until `hasMessageAvailable` 
doesn't return `ResultNotConnected`, e.g.
   
   ```c++
       bool hasMessageAvailable;
       while (reader.hasMessageAvailable(hasMessageAvailable) == 
ResultNotConnected) {
           std::this_thread::sleep_for(std::chrono::milliseconds(100));
       }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to