Skip to content

Commit 19e0a23

Browse files
author
vasmith
committed
Added option to maintain AddressResolver address order for AutoRecoveringConnection
1 parent 39fe122 commit 19e0a23

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/rabbitmq/client/impl/ConnectionParams.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ConnectionParams {
4949
private ExecutorService topologyRecoveryExecutor;
5050
private int channelRpcTimeout;
5151
private boolean channelShouldCheckRpcResponseType;
52+
private boolean maintainAddressOrder;
5253
private ErrorOnWriteListener errorOnWriteListener;
5354
private int workPoolTimeout = -1;
5455
private TopologyRecoveryFilter topologyRecoveryFilter;
@@ -287,4 +288,12 @@ public void setCredentialsRefreshService(CredentialsRefreshService credentialsRe
287288
public CredentialsRefreshService getCredentialsRefreshService() {
288289
return credentialsRefreshService;
289290
}
291+
292+
public boolean shouldMaintainAddressOrder() {
293+
return maintainAddressOrder;
294+
}
295+
296+
public void setMaintainAddressOrder(boolean maintainAddressOrder) {
297+
this.maintainAddressOrder = maintainAddressOrder;
298+
}
290299
}

src/main/java/com/rabbitmq/client/impl/recovery/RecoveryAwareAMQConnectionFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public RecoveryAwareAMQConnectionFactory(ConnectionParams params, FrameHandlerFa
5555
// package protected API, made public for testing only
5656
public RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutException {
5757
Exception lastException = null;
58-
List<Address> shuffled = shuffle(addressResolver.getAddresses());
58+
List<Address> originalOrder = addressResolver.getAddresses();
59+
List<Address> shuffled = params.shouldMaintainAddressOrder() ? originalOrder : shuffle(originalOrder);
5960

6061
for (Address addr : shuffled) {
6162
try {

0 commit comments

Comments
 (0)