BewareMyPower commented on code in PR #54:
URL: https://github.com/apache/pulsar-client-cpp/pull/54#discussion_r1000139623
##########
lib/ConsumerImpl.cc:
##########
@@ -990,20 +1002,25 @@ void ConsumerImpl::negativeAcknowledge(const MessageId&
messageId) {
void ConsumerImpl::disconnectConsumer() {
LOG_INFO("Broker notification of Closed consumer: " << consumerId_);
- Lock lock(mutex_);
- connection_.reset();
- lock.unlock();
+ resetCnx();
scheduleReconnection(get_shared_this_ptr());
}
-void ConsumerImpl::closeAsync(ResultCallback callback) {
- // Keep a reference to ensure object is kept alive
- ConsumerImplPtr ptr = get_shared_this_ptr();
+void ConsumerImpl::closeAsync(ResultCallback originalCallback) {
+ auto callback = [this, originalCallback](Result result) {
+ shutdown();
Review Comment:
> When closing the consumer, we also need to remove the client connection
There is an important point that when `HandlerBase::connection_` is
modified, we should unregister itself from the connection. Otherwise, the
producer or consumer will always be cached in `ClientConnection`. So this PR
addes a `beforeConnectionChange` method, which is always called when `setCnx`
or `resetCnx` is called.
The `cnx->removeConsumer` is called in
`ConsumerImpl::beforeConnectionChange`. Since `shutdown` calls `resetCnx()`,
this method is implicitly called in `shutdown`.
Without this design, users have to remove producer or consumer each time the
connection changed, like:
```c++
auto cnx = getCnx().lock();
if (cnx) {
cnx->removeConsumer(consumerId_);
}
connection_ = newConnection;
```
```c++
auto cnx = getCnx().lock();
if (cnx) {
cnx->removeConsumer(consumerId_);
}
connection_.reset();
```
--
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]