@@ -257,10 +257,18 @@ static NativeConnectionWrapper enforceAffinity(
257
257
connectionWrapper = connectionFactory .apply (null );
258
258
management .init ();
259
259
info = management .queueInfo (affinity .queue ());
260
+ affinityCache .queueInfo (info );
260
261
queueInfoRefreshed = true ;
261
262
}
263
+ LOGGER .debug (
264
+ "Looking affinity with queue '{}' (type = {}, leader = {}, replicas = {})" ,
265
+ info .name (),
266
+ info .type (),
267
+ info .leader (),
268
+ info .replicas ());
262
269
if (nodesWithAffinity == null ) {
263
270
nodesWithAffinity = ConnectionUtils .findAffinity (affinity , info );
271
+ LOGGER .debug ("Nodes matching affinity {}: {}" , affinity , nodesWithAffinity );
264
272
}
265
273
if (connectionWrapper == null ) {
266
274
List <Address > addressHints =
@@ -269,28 +277,31 @@ static NativeConnectionWrapper enforceAffinity(
269
277
.filter (Objects ::nonNull )
270
278
.collect (Collectors .toList ());
271
279
connectionWrapper = connectionFactory .apply (addressHints );
272
- affinityCache .nodenameToAddress (connectionWrapper .nodename , connectionWrapper .address );
273
280
}
274
281
LOGGER .debug ("Currently connected to node {}" , connectionWrapper .nodename );
282
+ affinityCache .nodenameToAddress (connectionWrapper .nodename , connectionWrapper .address );
275
283
if (nodesWithAffinity .contains (connectionWrapper .nodename )) {
276
284
LOGGER .debug ("Affinity {} found with node {}" , affinity , connectionWrapper .nodename );
277
285
pickedConnection = connectionWrapper ;
278
286
} else if (attemptCount == 5 ) {
279
287
LOGGER .debug (
280
- "Could not find affinity {} after {} attempt(s), using last connection" ,
288
+ "Could not find affinity {} after {} attempt(s), using last connection. " ,
281
289
affinity ,
282
290
attemptCount );
283
291
pickedConnection = connectionWrapper ;
284
292
} else {
285
- LOGGER .debug ("Affinity {} not found with node {}" , affinity , connectionWrapper .nodename );
293
+ LOGGER .debug ("Affinity {} not found with node {}. " , affinity , connectionWrapper .nodename );
286
294
if (!queueInfoRefreshed ) {
295
+ LOGGER .debug ("Refreshing queue information." );
287
296
management .init ();
288
297
info = management .queueInfo (affinity .queue ());
289
298
affinityCache .queueInfo (info );
299
+ nodesWithAffinity = ConnectionUtils .findAffinity (affinity , info );
300
+ LOGGER .debug ("Nodes matching affinity {}: {}" , affinity , nodesWithAffinity );
290
301
queueInfoRefreshed = true ;
291
302
}
292
- connectionWrapper .connection .close ();
293
303
management .releaseResources ();
304
+ connectionWrapper .connection .close ();
294
305
}
295
306
}
296
307
return pickedConnection ;
0 commit comments