merlimat commented on a change in pull request #1996: Cpp client: add
multiTopicsConsumer
URL: https://github.com/apache/incubator-pulsar/pull/1996#discussion_r197870080
##########
File path: pulsar-client-cpp/lib/ClientImpl.cc
##########
@@ -209,6 +211,42 @@ void ClientImpl::handleReaderMetadataLookup(const Result
result, const LookupDat
consumers_.push_back(reader->getConsumer());
}
+void ClientImpl::subscribeAsync(const std::vector<std::string>& topics, const
std::string& consumerName,
+ const ConsumerConfiguration& conf,
SubscribeCallback callback) {
+ TopicNamePtr topicNamePtr;
+ {
+ Lock lock(mutex_);
+ if (state_ != Open) {
+ lock.unlock();
+ callback(ResultAlreadyClosed, Consumer());
+ return;
+ } else {
+ lock.unlock();
+ if (!topics.empty() && !(topicNamePtr =
MultiTopicsConsumerImpl::topicNamesValid(topics))) {
+ callback(ResultInvalidTopicName, Consumer());
+ return;
+ }
+ }
+ }
+
+ if (topicNamePtr) {
+ std::string randomName = generateRandomName();
+ std::stringstream consumerTopicNameStream;
+ consumerTopicNameStream << topicNamePtr->toString() <<
"-TopicsConsumerFakeName-" << randomName;
+ topicNamePtr = TopicName::get(consumerTopicNameStream.str());
+ }
+
+ ConsumerImplBasePtr consumer = boost::make_shared<MultiTopicsConsumerImpl>(
+ shared_from_this(), topics, consumerName, topicNamePtr, conf,
lookupServicePtr_);
+
+ consumer->getConsumerCreatedFuture().addListener(
+ boost::bind(&ClientImpl::handleConsumerCreated, shared_from_this(),
_1, _2, callback, consumer));
+ Lock lock(mutex_);
Review comment:
Since we're acquiring the mutex above as well, I'd rather have a single
continuous section with the mutex
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services