21
21
import java .security .NoSuchAlgorithmException ;
22
22
import java .util .Collections ;
23
23
import java .util .Map ;
24
+ import java .util .HashMap ;
24
25
import java .util .concurrent .*;
25
26
import java .util .List ;
26
27
import java .util .Arrays ;
@@ -647,6 +648,20 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce
647
648
return newConnection (this .sharedExecutor , Arrays .asList (addrs ), null );
648
649
}
649
650
651
+
652
+ /**
653
+ * Create a new broker connection, picking the first available address from
654
+ * the list.
655
+ *
656
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
657
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
658
+ * reconnection attempts will pick a random accessible address from the provided list.
659
+ *
660
+ * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
661
+ * @param connectionName arbitrary sring for connection name client property
662
+ * @return an interface to the connection
663
+ * @throws IOException if it encounters a problem
664
+ */
650
665
public Connection newConnection (Address [] addrs , String connectionName ) throws IOException , TimeoutException {
651
666
return newConnection (this .sharedExecutor , Arrays .asList (addrs ), connectionName );
652
667
}
@@ -667,6 +682,19 @@ public Connection newConnection(List<Address> addrs) throws IOException, Timeout
667
682
return newConnection (this .sharedExecutor , addrs , null );
668
683
}
669
684
685
+ /**
686
+ * Create a new broker connection, picking the first available address from
687
+ * the list.
688
+ *
689
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
690
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
691
+ * reconnection attempts will pick a random accessible address from the provided list.
692
+ *
693
+ * @param addrs a List of known broker addresses (hostname/port pairs) to try in order
694
+ * @param connectionName arbitrary sring for connection name client property
695
+ * @return an interface to the connection
696
+ * @throws IOException if it encounters a problem
697
+ */
670
698
public Connection newConnection (List <Address > addrs , String connectionName ) throws IOException , TimeoutException {
671
699
return newConnection (this .sharedExecutor , addrs , connectionName );
672
700
}
@@ -689,6 +717,22 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw
689
717
return newConnection (executor , Arrays .asList (addrs ), null );
690
718
}
691
719
720
+
721
+ /**
722
+ * Create a new broker connection, picking the first available address from
723
+ * the list.
724
+ *
725
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
726
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
727
+ * reconnection attempts will pick a random accessible address from the provided list.
728
+ *
729
+ * @param executor thread execution service for consumers on the connection
730
+ * @param addrs an array of known broker addresses (hostname/port pairs) to try in order
731
+ * @param connectionName arbitrary sring for connection name client property
732
+ * @return an interface to the connection
733
+ * @throws java.io.IOException if it encounters a problem
734
+ * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
735
+ */
692
736
public Connection newConnection (ExecutorService executor , Address [] addrs , String connectionName ) throws IOException , TimeoutException {
693
737
return newConnection (executor , Arrays .asList (addrs ), connectionName );
694
738
}
@@ -707,13 +751,33 @@ public Connection newConnection(ExecutorService executor, Address[] addrs, Strin
707
751
* @throws java.io.IOException if it encounters a problem
708
752
* @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
709
753
*/
754
+ public Connection newConnection (ExecutorService executor , List <Address > addrs ) throws IOException , TimeoutException {
755
+ return newConnection (executor , addrs , null );
756
+ }
757
+
758
+ /**
759
+ * Create a new broker connection, picking the first available address from
760
+ * the list.
761
+ *
762
+ * If <a href="http://www.rabbitmq.com/api-guide.html#recovery">automatic connection recovery</a>
763
+ * is enabled, the connection returned by this method will be {@link Recoverable}. Future
764
+ * reconnection attempts will pick a random accessible address from the provided list.
765
+ *
766
+ * @param executor thread execution service for consumers on the connection
767
+ * @param addrs a List of known broker addrs (hostname/port pairs) to try in order
768
+ * @param connectionName arbitrary sring for connection name client property
769
+ * @return an interface to the connection
770
+ * @throws java.io.IOException if it encounters a problem
771
+ * @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
772
+ */
710
773
public Connection newConnection (ExecutorService executor , List <Address > addrs , String connectionName )
711
774
throws IOException , TimeoutException {
712
775
// make sure we respect the provided thread factory
713
776
FrameHandlerFactory fhFactory = createFrameHandlerFactory ();
714
777
ConnectionParams params = params (executor );
778
+ // set connection name client property
715
779
if (connectionName != null ) {
716
- Map <String , Object > properties = params .getClientProperties (). clone ( );
780
+ Map <String , Object > properties = new HashMap < String , Object >( params .getClientProperties ());
717
781
properties .put ("connection_name" , connectionName );
718
782
params .setClientProperties (properties );
719
783
}
0 commit comments