BewareMyPower commented on code in PR #17162:
URL: https://github.com/apache/pulsar/pull/17162#discussion_r958037731
##########
pulsar-client-cpp/lib/ClientImpl.cc:
##########
@@ -414,36 +402,32 @@ void ClientImpl::handleConsumerCreated(Result result,
ConsumerImplBaseWeakPtr co
Future<Result, ClientConnectionWeakPtr> ClientImpl::getConnection(const
std::string& topic) {
Promise<Result, ClientConnectionWeakPtr> promise;
-
lookupServicePtr_->lookupAsync(topic).addListener(std::bind(&ClientImpl::handleLookup,
shared_from_this(),
-
std::placeholders::_1, std::placeholders::_2,
- promise));
- return promise.getFuture();
-}
-void ClientImpl::handleLookup(Result result, LookupDataResultPtr data,
- Promise<Result, ClientConnectionWeakPtr>
promise) {
- if (data) {
- const std::string& logicalAddress =
- clientConfiguration_.isUseTls() ? data->getBrokerUrlTls() :
data->getBrokerUrl();
- LOG_DEBUG("Getting connection to broker: " << logicalAddress);
- const std::string& physicalAddress =
- data->shouldProxyThroughServiceUrl() ? serviceUrl_ :
logicalAddress;
- Future<Result, ClientConnectionWeakPtr> future =
- pool_.getConnectionAsync(logicalAddress, physicalAddress);
- future.addListener(std::bind(&ClientImpl::handleNewConnection,
shared_from_this(),
- std::placeholders::_1,
std::placeholders::_2, promise));
- } else {
- promise.setFailed(result);
+ const auto topicNamePtr = TopicName::get(topic);
+ if (!topicNamePtr) {
+ LOG_ERROR("Unable to parse topic - " << topic);
+ promise.setFailed(ResultInvalidTopicName);
+ return promise.getFuture();
}
-}
-void ClientImpl::handleNewConnection(Result result, const
ClientConnectionWeakPtr& conn,
- Promise<Result, ClientConnectionWeakPtr>
promise) {
- if (result == ResultOk) {
- promise.setValue(conn);
- } else {
- promise.setFailed(ResultConnectError);
- }
+ auto self = shared_from_this();
+ lookupServicePtr_->getBroker(*topicNamePtr)
Review Comment:
But it should be okay in this PR. Because only the returned `std::string` is
used in `getBroker` method. But if we applied the retry logic in future, it
would be a problem.
--
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]