You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/07/24 08:09:18 UTC

[GitHub] [pulsar] BewareMyPower opened a new issue, #16761: [C++] getLastMessageIdAsync returns ResultNotConnected after seek

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: commits-unsubscribe@pulsar.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] RobertIndie closed issue #16761: [C++] getLastMessageIdAsync returns ResultNotConnected after seek

Posted by GitBox <gi...@apache.org>.
RobertIndie closed issue #16761: [C++] getLastMessageIdAsync returns ResultNotConnected after seek
URL: https://github.com/apache/pulsar/issues/16761


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org