File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
src/test/java/com/rabbitmq/client/amqp/impl Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 22
22
import static org .assertj .core .api .Assertions .assertThat ;
23
23
24
24
import com .rabbitmq .client .amqp .*;
25
+ import java .util .List ;
26
+ import java .util .concurrent .atomic .AtomicInteger ;
25
27
import java .util .function .Consumer ;
26
28
import org .junit .jupiter .api .*;
27
29
@@ -39,6 +41,7 @@ void init(TestInfo info) {
39
41
environment =
40
42
new AmqpEnvironmentBuilder ()
41
43
.connectionSettings ()
44
+ .addressSelector (new RoundRobinAddressSelector ())
42
45
.uris ("amqp://localhost:5672" , "amqp://localhost:5673" , "amqp://localhost:5674" )
43
46
.environmentBuilder ()
44
47
.build ();
@@ -74,4 +77,20 @@ AmqpConnection connection(Consumer<ConnectionBuilder> operation) {
74
77
operation .accept (builder );
75
78
return (AmqpConnection ) builder .build ();
76
79
}
80
+
81
+ private static class RoundRobinAddressSelector implements AddressSelector {
82
+
83
+ private final AtomicInteger count = new AtomicInteger ();
84
+
85
+ @ Override
86
+ public Address select (List <Address > addresses ) {
87
+ if (addresses .isEmpty ()) {
88
+ throw new IllegalStateException ("There should at least one node to connect to" );
89
+ } else if (addresses .size () == 1 ) {
90
+ return addresses .get (0 );
91
+ } else {
92
+ return addresses .get (count .getAndIncrement () % addresses .size ());
93
+ }
94
+ }
95
+ }
77
96
}
You can’t perform that action at this time.
0 commit comments