BewareMyPower edited a comment on issue #8846:
URL: https://github.com/apache/pulsar/issues/8846#issuecomment-739987242
I think the issue is similar to #8300 . But unlike the Java Client, C++ API
only exposes the receive callback so there's no case like a future of receive
is cancelled but the associated pending receive is still in the queue.
The C++ client's receive logic is more simple:
1. Add a pending receive when `receiveAsync` is called.
2. Remove a pending receive when an incoming messages is received by
`ClientConnection`, while the callback of `receiveAsync` is called.
3. Clear all pending receives and complete all associated callbacks when the
consumer is closed.
If you want to cancel a pending receive, the only way is to close the
consumer. So adding a receive count limit is needed.
By the way, if you don't want to introduce the conditional variable and
notify/wait, a simple way is:
```c++
std::atomic_int numPendingReceives{0};
for (int i = 0; i < 100000; i++) {
if (++numPendingReceives >= 1000) {
// TODO: wait for a few milliseconds? or sending alarms?
}
consumer.receiveAsync([&numPendingReceives](Result result, const
Message& msg) {
numPendingReceives--;
if (result == ResultOk) {
// TODO: process `msg`
} else {
// TODO: handle error
}
});
// do other things here...
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]