@@ -661,6 +661,23 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce
661
661
return newConnection (this .sharedExecutor , Arrays .asList (addrs ), null );
662
662
}
663
663
664
+ /**
665
+ * Create a new broker connection, picking the first available address from
666
+ * the list provided by the {@link AddressResolver}.
667
+ *
668
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
669
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
670
+ * reconnection attempts will pick a random accessible address provided by the {@link AddressResolver}.
671
+ *
672
+ * @param addressResolver discovery service to list potential addresses (hostname/port pairs) to connect to
673
+ * @return an interface to the connection
674
+ * @throws IOException if it encounters a problem
675
+ * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
676
+ */
677
+ public Connection newConnection (AddressResolver addressResolver ) throws IOException , TimeoutException {
678
+ return newConnection (this .sharedExecutor , addressResolver , null );
679
+ }
680
+
664
681
665
682
/**
666
683
* Create a new broker connection with a client-provided name, picking the first available address from
@@ -780,6 +797,24 @@ public Connection newConnection(ExecutorService executor, List<Address> addrs) t
780
797
return newConnection (executor , addrs , null );
781
798
}
782
799
800
+ /**
801
+ * Create a new broker connection, picking the first available address from
802
+ * the list provided by the {@link AddressResolver}.
803
+ *
804
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
805
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
806
+ * reconnection attempts will pick a random accessible address provided by the {@link AddressResolver}.
807
+ *
808
+ * @param executor thread execution service for consumers on the connection
809
+ * @param addressResolver discovery service to list potential addresses (hostname/port pairs) to connect to
810
+ * @return an interface to the connection
811
+ * @throws java.io.IOException if it encounters a problem
812
+ * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
813
+ */
814
+ public Connection newConnection (ExecutorService executor , AddressResolver addressResolver ) throws IOException , TimeoutException {
815
+ return newConnection (executor , addressResolver , null );
816
+ }
817
+
783
818
/**
784
819
* Create a new broker connection with a client-provided name, picking the first available address from
785
820
* the list.
@@ -801,6 +836,30 @@ public Connection newConnection(ExecutorService executor, List<Address> addrs) t
801
836
*/
802
837
public Connection newConnection (ExecutorService executor , List <Address > addrs , String clientProvidedName )
803
838
throws IOException , TimeoutException {
839
+ return newConnection (executor , new ListAddressResolver (addrs ), clientProvidedName );
840
+ }
841
+
842
+ /**
843
+ * Create a new broker connection with a client-provided name, picking the first available address from
844
+ * the list provided by the {@link AddressResolver}.
845
+ *
846
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
847
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
848
+ * reconnection attempts will pick a random accessible address provided by the {@link AddressResolver}.
849
+ *
850
+ * @param executor thread execution service for consumers on the connection
851
+ * @param addressResolver discovery service to list potential addresses (hostname/port pairs) to connect to
852
+ * @param clientProvidedName application-specific connection name, will be displayed
853
+ * in the management UI if RabbitMQ server supports it.
854
+ * This value doesn't have to be unique and cannot be used
855
+ * as a connection identifier e.g. in HTTP API requests.
856
+ * This value is supposed to be human-readable.
857
+ * @return an interface to the connection
858
+ * @throws java.io.IOException if it encounters a problem
859
+ * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
860
+ */
861
+ public Connection newConnection (ExecutorService executor , AddressResolver addressResolver , String clientProvidedName )
862
+ throws IOException , TimeoutException {
804
863
// make sure we respect the provided thread factory
805
864
FrameHandlerFactory fhFactory = createFrameHandlerFactory ();
806
865
ConnectionParams params = params (executor );
@@ -813,11 +872,12 @@ public Connection newConnection(ExecutorService executor, List<Address> addrs, S
813
872
814
873
if (isAutomaticRecoveryEnabled ()) {
815
874
// see com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory#newConnection
816
- AutorecoveringConnection conn = new AutorecoveringConnection (params , fhFactory , addrs );
875
+ AutorecoveringConnection conn = new AutorecoveringConnection (params , fhFactory , addressResolver );
817
876
818
877
conn .init ();
819
878
return conn ;
820
879
} else {
880
+ List <Address > addrs = addressResolver .getAddresses ();
821
881
IOException lastException = null ;
822
882
for (Address addr : addrs ) {
823
883
try {
0 commit comments