2424import io .opentelemetry .api .common .Attributes ;
2525import java .net .InetSocketAddress ;
2626import java .net .URI ;
27+ import java .util .Map ;
2728import java .util .Optional ;
2829import java .util .concurrent .CompletableFuture ;
2930import java .util .concurrent .ConcurrentHashMap ;
3233import java .util .concurrent .TimeUnit ;
3334import java .util .concurrent .atomic .AtomicLong ;
3435import org .apache .commons .lang3 .mutable .MutableObject ;
36+ import org .apache .commons .lang3 .tuple .Pair ;
3537import org .apache .pulsar .client .api .PulsarClientException ;
3638import org .apache .pulsar .client .api .SchemaSerializationException ;
3739import org .apache .pulsar .client .impl .metrics .LatencyHistogram ;
@@ -60,7 +62,7 @@ public class BinaryProtoLookupService implements LookupService {
6062 private final String listenerName ;
6163 private final int maxLookupRedirects ;
6264
63- private final ConcurrentHashMap <TopicName , CompletableFuture <LookupTopicResult >>
65+ private final ConcurrentHashMap <Pair < TopicName , Map < String , String >> , CompletableFuture <LookupTopicResult >>
6466 lookupInProgress = new ConcurrentHashMap <>();
6567
6668 private final ConcurrentHashMap <TopicName , CompletableFuture <PartitionedTopicMetadata >>
@@ -118,10 +120,12 @@ public void updateServiceUrl(String serviceUrl) throws PulsarClientException {
118120 public CompletableFuture <LookupTopicResult > getBroker (TopicName topicName ) {
119121 long startTime = System .nanoTime ();
120122 final MutableObject <CompletableFuture > newFutureCreated = new MutableObject <>();
123+ final Pair <TopicName , Map <String , String >> key = Pair .of (topicName ,
124+ client .getConfiguration ().getLookupProperties ());
121125 try {
122- return lookupInProgress .computeIfAbsent (topicName , tpName -> {
123- CompletableFuture <LookupTopicResult > newFuture =
124- findBroker ( serviceNameResolver . resolveHost (), false , topicName , 0 );
126+ return lookupInProgress .computeIfAbsent (key , tpName -> {
127+ CompletableFuture <LookupTopicResult > newFuture = findBroker ( serviceNameResolver . resolveHost (), false ,
128+ topicName , 0 , key . getRight () );
125129 newFutureCreated .setValue (newFuture );
126130
127131 newFuture .thenRun (() -> {
@@ -135,7 +139,7 @@ public CompletableFuture<LookupTopicResult> getBroker(TopicName topicName) {
135139 } finally {
136140 if (newFutureCreated .getValue () != null ) {
137141 newFutureCreated .getValue ().whenComplete ((v , ex ) -> {
138- lookupInProgress .remove (topicName , newFutureCreated .getValue ());
142+ lookupInProgress .remove (key , newFutureCreated .getValue ());
139143 });
140144 }
141145 }
@@ -167,7 +171,7 @@ public CompletableFuture<PartitionedTopicMetadata> getPartitionedTopicMetadata(
167171 }
168172
169173 private CompletableFuture <LookupTopicResult > findBroker (InetSocketAddress socketAddress ,
170- boolean authoritative , TopicName topicName , final int redirectCount ) {
174+ boolean authoritative , TopicName topicName , final int redirectCount , Map < String , String > properties ) {
171175 CompletableFuture <LookupTopicResult > addressFuture = new CompletableFuture <>();
172176
173177 if (maxLookupRedirects > 0 && redirectCount > maxLookupRedirects ) {
@@ -179,7 +183,7 @@ private CompletableFuture<LookupTopicResult> findBroker(InetSocketAddress socket
179183 client .getCnxPool ().getConnection (socketAddress ).thenAccept (clientCnx -> {
180184 long requestId = client .newRequestId ();
181185 ByteBuf request = Commands .newLookup (topicName .toString (), listenerName , authoritative , requestId ,
182- client . getConfiguration (). getLookupProperties () );
186+ properties );
183187 clientCnx .newLookup (request , requestId ).whenComplete ((r , t ) -> {
184188 if (t != null ) {
185189 // lookup failed
@@ -204,7 +208,7 @@ private CompletableFuture<LookupTopicResult> findBroker(InetSocketAddress socket
204208
205209 // (2) redirect to given address if response is: redirect
206210 if (r .redirect ) {
207- findBroker (responseBrokerAddress , r .authoritative , topicName , redirectCount + 1 )
211+ findBroker (responseBrokerAddress , r .authoritative , topicName , redirectCount + 1 , properties )
208212 .thenAccept (addressFuture ::complete )
209213 .exceptionally ((lookupException ) -> {
210214 Throwable cause = FutureUtil .unwrapCompletionException (lookupException );
0 commit comments