Skip to content

Commit b709f6b

Browse files
authored
Merge pull request #691 from rabbitmq/optional-reshuffling-in-address-resolver
Move resolved address shuffling to AddressResolver
2 parents 39fe122 + a4e76fb commit b709f6b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main/java/com/rabbitmq/client/AddressResolver.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package com.rabbitmq.client;
1717

1818
import java.io.IOException;
19+
import java.util.ArrayList;
20+
import java.util.Collections;
1921
import java.util.List;
2022

2123
/**
@@ -30,4 +32,9 @@ public interface AddressResolver {
3032
*/
3133
List<Address> getAddresses() throws IOException;
3234

35+
default List<Address> maybeShuffle(List<Address> input) {
36+
List<Address> list = new ArrayList<Address>(input);
37+
Collections.shuffle(list);
38+
return list;
39+
}
3340
}

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> resolved = addressResolver.getAddresses();
59+
List<Address> shuffled = addressResolver.maybeShuffle(resolved);
5960

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

0 commit comments

Comments
 (0)