BewareMyPower commented on pull request #15009:
URL: https://github.com/apache/pulsar/pull/15009#issuecomment-1086840315
In addition to the test, I tried to schedule reconnection to a remote
endpoint periodically.
```c++
Producer producer;
auto result = client.createProducer("topic-1", producer);
ASSERT_EQ(result, ResultOk);
for (int i = 0; i < 100000; i++) {
auto state = PulsarFriend::reconnection(producer);
LOG_INFO(i << " reconnection: " << state);
std::this_thread::sleep_for(std::chrono::seconds(1));
}
```
The helper method in `PulsarFriend` is
```c++
static HandlerBase::State reconnection(Producer producer) {
auto impl = std::static_pointer_cast<ProducerImpl>(producer.impl_);
impl->connection_.reset();
impl->state_ = HandlerBase::State::Pending;
HandlerBase::scheduleReconnection(std::static_pointer_cast<HandlerBase>(impl));
for (int i = 0; i < 1000; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::lock_guard<std::mutex> lock(impl->mutex_);
if (impl->state_ == HandlerBase::State::Ready) {
break;
}
}
std::lock_guard<std::mutex> lock(impl->mutex_);
return impl->state_;
}
```
--
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]