8000 Getter for connection name and docs · Donaldhan/rabbitmq-java-client@5066bcc · GitHub
[go: up one dir, main page]

Skip to content

Commit 5066bcc

Browse files
author
Daniil Fedotov
committed
Getter for connection name and docs
1 parent 20f1fb6 commit 5066bcc

File tree

4 files changed

+88
-1
lines changed

4 files changed

+88
-1
lines changed

src/com/rabbitmq/client/Connection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti
9393
*/
9494
Map<String, Object> getClientProperties();
9595

96+
/**
97+
* Get connection name client property value
98+
*
99+
* @return string connection name from client properties, or null if there is not such property.
100+
*/
101+
String getConnectionName();
102+
96103
/**
97104
* Retrieve the server properties.
98105
* @return a map of the server properties. This typically includes the product name and version of the server.

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.security.NoSuchAlgorithmException;
2222
import java.util.Collections;
2323
import java.util.Map;
24+
import java.util.HashMap;
2425
import java.util.concurrent.*;
2526
import java.util.List;
2627
import java.util.Arrays;
@@ -647,6 +648,20 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce
647648
return newConnection(this.sharedExecutor, Arrays.asList(addrs), null);
648649
}
649650

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+
*/
650665
public Connection newConnection(Address[] addrs, String connectionName) throws IOException, TimeoutException {
651666
return newConnection(this.sharedExecutor, Arrays.asList(addrs), connectionName);
652667
}
@@ -667,6 +682,19 @@ public Connection newConnection(List<Address> addrs) throws IOException, Timeout
667682
return newConnection(this.sharedExecutor, addrs, null);
668683
}
669684

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+
*/
670698
public Connection newConnection(List<Address> addrs, String connectionName) throws IOException, TimeoutException {
671699
return newConnection(this.sharedExecutor, addrs, connectionName);
672700
}
@@ -689,6 +717,22 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw
689717
return newConnection(executor, Arrays.asList(addrs), null);
690718
}
691719

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+
*/
692736
public Connection newConnection(ExecutorService executor, Address[] addrs, String connectionName) throws IOException, TimeoutException {
693737
return newConnection(executor, Arrays.asList(addrs), connectionName);
694738
}
@@ -707,13 +751,33 @@ public Connection newConnection(ExecutorService executor, Address[] addrs, Strin
707751
* @throws java.io.IOException if it encounters a problem
708752
* @see <a href="http://www.rabbitmq.com/api-guide.html#recovery">Automatic Recovery</a>
709753
*/
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+
*/
710773
public Connection newConnection(ExecutorService executor, List<Address> addrs, String connectionName)
711774
throws IOException, TimeoutException {
712775
// make sure we respect the provided thread factory
713776
FrameHandlerFactory fhFactory = createFrameHandlerFactory();
714777
ConnectionParams params = params(executor);
778+
// set connection name client property
715779
if (connectionName != null) {
716-
Map<String, Object> properties = params.getClientProperties().clone();
780+
Map<String, Object> properties = new HashMap<String, Object>(params.getClientProperties());
717781
properties.put("connection_name", connectionName);
718782
params.setClientProperties(properties);
719783
}

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ public Map<String, Object> getClientProperties() {
470470
return new HashMap<String, Object>(_clientProperties);
471471
}
472472

473+
public String getConnectionName() {
474+
Object connectionName = _clientProperties.get("connection_name");
475+
if (connectionName == null){
476+
return null;
477+
} else {
478+
return connectionName.toString();
479+
}
480+
}
481+
473482
/**
474483
* Protected API - retrieve the current ExceptionHandler
475484
*/

src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ public Map<String, Object> getClientProperties() {
156156
return delegate.getClientProperties();
157157
}
158158

159+
/**
160+
* @see com.rabbitmq.client.Connection#getConnectionName()
161+
*/
162+
public String getConnectionName() {
163+
return delegate.getConnectionName();
164+
}
165+
159166
/**
160167
* @see com.rabbitmq.client.Connection#getFrameMax()
161168
*/

0 commit comments

Comments
 (0)
0