From 20f1fb62940339d63fc2f117531ac1d99bcf8cbc Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Mon, 11 Apr 2016 17:21:45 +0100 Subject: [PATCH 1/4] Connection name parameter to create connections --- .../rabbitmq/client/ConnectionFactory.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/com/rabbitmq/client/ConnectionFactory.java b/src/com/rabbitmq/client/ConnectionFactory.java index 191175180b..1ea28a2e9b 100644 --- a/src/com/rabbitmq/client/ConnectionFactory.java +++ b/src/com/rabbitmq/client/ConnectionFactory.java @@ -644,7 +644,11 @@ protected FrameHandlerFactory createFrameHandlerFactory() throws IOException { * @throws IOException if it encounters a problem */ public Connection newConnection(Address[] addrs) throws IOException, TimeoutException { - return newConnection(this.sharedExecutor, Arrays.asList(addrs)); + return newConnection(this.sharedExecutor, Arrays.asList(addrs), null); + } + + public Connection newConnection(Address[] addrs, String connectionName) throws IOException, TimeoutException { + return newConnection(this.sharedExecutor, Arrays.asList(addrs), connectionName); } /** @@ -660,7 +664,11 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce * @throws IOException if it encounters a problem */ public Connection newConnection(List
addrs) throws IOException, TimeoutException { - return newConnection(this.sharedExecutor, addrs); + return newConnection(this.sharedExecutor, addrs, null); + } + + public Connection newConnection(List
addrs, String connectionName) throws IOException, TimeoutException { + return newConnection(this.sharedExecutor, addrs, connectionName); } /** @@ -678,7 +686,11 @@ public Connection newConnection(List
addrs) throws IOException, Timeout * @see Automatic Recovery */ public Connection newConnection(ExecutorService executor, Address[] addrs) throws IOException, TimeoutException { - return newConnection(executor, Arrays.asList(addrs)); + return newConnection(executor, Arrays.asList(addrs), null); + } + + public Connection newConnection(ExecutorService executor, Address[] addrs, String connectionName) throws IOException, TimeoutException { + return newConnection(executor, Arrays.asList(addrs), connectionName); } /** @@ -695,11 +707,16 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw * @throws java.io.IOException if it encounters a problem * @see Automatic Recovery */ - public Connection newConnection(ExecutorService executor, List
addrs) + public Connection newConnection(ExecutorService executor, List
addrs, String connectionName) throws IOException, TimeoutException { // make sure we respect the provided thread factory FrameHandlerFactory fhFactory = createFrameHandlerFactory(); ConnectionParams params = params(executor); + if (connectionName != null) { + Map properties = params.getClientProperties().clone(); + properties.put("connection_name", connectionName); + params.setClientProperties(properties); + } if (isAutomaticRecoveryEnabled()) { // see com.rabbitmq.client.impl.recovery.RecoveryAwareAMQConnectionFactory#newConnection From 5066bccc4d1fd6d8bc4d6779954055cc0f86ec5c Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Tue, 12 Apr 2016 12:50:10 +0100 Subject: [PATCH 2/4] Getter for connection name and docs --- src/com/rabbitmq/client/Connection.java | 7 ++ .../rabbitmq/client/ConnectionFactory.java | 66 ++++++++++++++++++- .../rabbitmq/client/impl/AMQConnection.java | 9 +++ .../recovery/AutorecoveringConnection.java | 7 ++ 4 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/com/rabbitmq/client/Connection.java b/src/com/rabbitmq/client/Connection.java index e733ce957a..95d6445f69 100644 --- a/src/com/rabbitmq/client/Connection.java +++ b/src/com/rabbitmq/client/Connection.java @@ -93,6 +93,13 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti */ Map getClientProperties(); + /** + * Get connection name client property value + * + * @return string connection name from client properties, or null if there is not such property. + */ + String getConnectionName(); + /** * Retrieve the server properties. * @return a map of the server properties. This typically includes the product name and version of the server. diff --git a/src/com/rabbitmq/client/ConnectionFactory.java b/src/com/rabbitmq/client/ConnectionFactory.java index 1ea28a2e9b..9c005370f8 100644 --- a/src/com/rabbitmq/client/ConnectionFactory.java +++ b/src/com/rabbitmq/client/ConnectionFactory.java @@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Collections; import java.util.Map; +import java.util.HashMap; import java.util.concurrent.*; import java.util.List; import java.util.Arrays; @@ -647,6 +648,20 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce return newConnection(this.sharedExecutor, Arrays.asList(addrs), null); } + + /** + * Create a new broker connection, picking the first available address from + * the list. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Future + * reconnection attempts will pick a random accessible address from the provided list. + * + * @param addrs an array of known broker addresses (hostname/port pairs) to try in order + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws IOException if it encounters a problem + */ public Connection newConnection(Address[] addrs, String connectionName) throws IOException, TimeoutException { return newConnection(this.sharedExecutor, Arrays.asList(addrs), connectionName); } @@ -667,6 +682,19 @@ public Connection newConnection(List
addrs) throws IOException, Timeout return newConnection(this.sharedExecutor, addrs, null); } + /** + * Create a new broker connection, picking the first available address from + * the list. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Future + * reconnection attempts will pick a random accessible address from the provided list. + * + * @param addrs a List of known broker addresses (hostname/port pairs) to try in order + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws IOException if it encounters a problem + */ public Connection newConnection(List
addrs, String connectionName) throws IOException, TimeoutException { return newConnection(this.sharedExecutor, addrs, connectionName); } @@ -689,6 +717,22 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw return newConnection(executor, Arrays.asList(addrs), null); } + + /** + * Create a new broker connection, picking the first available address from + * the list. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Future + * reconnection attempts will pick a random accessible address from the provided list. + * + * @param executor thread execution service for consumers on the connection + * @param addrs an array of known broker addresses (hostname/port pairs) to try in order + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws java.io.IOException if it encounters a problem + * @see Automatic Recovery + */ public Connection newConnection(ExecutorService executor, Address[] addrs, String connectionName) throws IOException, TimeoutException { return newConnection(executor, Arrays.asList(addrs), connectionName); } @@ -707,13 +751,33 @@ public Connection newConnection(ExecutorService executor, Address[] addrs, Strin * @throws java.io.IOException if it encounters a problem * @see Automatic Recovery */ + public Connection newConnection(ExecutorService executor, List
addrs) throws IOException, TimeoutException { + return newConnection(executor, addrs, null); + } + + /** + * Create a new broker connection, picking the first available address from + * the list. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Future + * reconnection attempts will pick a random accessible address from the provided list. + * + * @param executor thread execution service for consumers on the connection + * @param addrs a List of known broker addrs (hostname/port pairs) to try in order + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws java.io.IOException if it encounters a problem + * @see Automatic Recovery + */ public Connection newConnection(ExecutorService executor, List
addrs, String connectionName) throws IOException, TimeoutException { // make sure we respect the provided thread factory FrameHandlerFactory fhFactory = createFrameHandlerFactory(); ConnectionParams params = params(executor); + // set connection name client property if (connectionName != null) { - Map properties = params.getClientProperties().clone(); + Map properties = new HashMap(params.getClientProperties()); properties.put("connection_name", connectionName); params.setClientProperties(properties); } diff --git a/src/com/rabbitmq/client/impl/AMQConnection.java b/src/com/rabbitmq/client/impl/AMQConnection.java index 54e17c0918..3634165950 100644 --- a/src/com/rabbitmq/client/impl/AMQConnection.java +++ b/src/com/rabbitmq/client/impl/AMQConnection.java @@ -470,6 +470,15 @@ public Map getClientProperties() { return new HashMap(_clientProperties); } + public String getConnectionName() { + Object connectionName = _clientProperties.get("connection_name"); + if (connectionName == null){ + return null; + } else { + return connectionName.toString(); + } + } + /** * Protected API - retrieve the current ExceptionHandler */ diff --git a/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java b/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java index b559625fb5..c7663d16b8 100644 --- a/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java +++ b/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java @@ -156,6 +156,13 @@ public Map getClientProperties() { return delegate.getClientProperties(); } + /** + * @see com.rabbitmq.client.Connection#getConnectionName() + */ + public String getConnectionName() { + return delegate.getConnectionName(); + } + /** * @see com.rabbitmq.client.Connection#getFrameMax() */ From f04af95e29683320c53d423956d211fa70da62eb Mon Sep 17 00:00:00 2001 From: Daniil Fedotov Date: Wed, 13 Apr 2016 12:53:03 +0100 Subject: [PATCH 3/4] Named connection tests --- .../rabbitmq/client/ConnectionFactory.java | 31 +++++++++++++++++ .../client/test/AMQConnectionTest.java | 33 +++++++++++++++++++ .../test/functional/ConnectionRecovery.java | 26 +++++++++++++++ 3 files changed, 90 insertions(+) diff --git a/src/com/rabbitmq/client/ConnectionFactory.java b/src/com/rabbitmq/client/ConnectionFactory.java index 9c005370f8..3eb7645745 100644 --- a/src/com/rabbitmq/client/ConnectionFactory.java +++ b/src/com/rabbitmq/client/ConnectionFactory.java @@ -841,6 +841,21 @@ public Connection newConnection() throws IOException, TimeoutException { return newConnection(this.sharedExecutor, Collections.singletonList(new Address(getHost(), getPort()))); } + /** + * Create a new broker connection. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Reconnection + * attempts will always use the address configured on {@link ConnectionFactory}. + * + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws IOException if it encounters a problem + */ + public Connection newConnection(String connectionName) throws IOException, TimeoutException { + return newConnection(this.sharedExecutor, Collections.singletonList(new Address(getHost(), getPort())), connectionName); + } + /** * Create a new broker connection. * @@ -856,6 +871,22 @@ public Connection newConnection(ExecutorService executor) throws IOException, Ti return newConnection(executor, Collections.singletonList(new Address(getHost(), getPort()))); } + /** + * Create a new broker connection. + * + * If automatic connection recovery + * is enabled, the connection returned by this method will be {@link Recoverable}. Reconnection + * attempts will always use the address configured on {@link ConnectionFactory}. + * + * @param executor thread execution service for consumers on the connection + * @param connectionName arbitrary sring for connection name client property + * @return an interface to the connection + * @throws IOException if it encounters a problem + */ + public Connection newConnection(ExecutorService executor, String connectionName) throws IOException, TimeoutException { + return newConnection(executor, Collections.singletonList(new Address(getHost(), getPort())), connectionName); + } + @Override public ConnectionFactory clone(){ try { return (ConnectionFactory)super.clone(); diff --git a/test/src/com/rabbitmq/client/test/AMQConnectionTest.java b/test/src/com/rabbitmq/client/test/AMQConnectionTest.java index 3aff2fbdd8..db650404cb 100644 --- a/test/src/com/rabbitmq/client/test/AMQConnectionTest.java +++ b/test/src/com/rabbitmq/client/test/AMQConnectionTest.java @@ -25,6 +25,9 @@ import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.TimeoutException; +import java.util.concurrent.ExecutorService; +import com.rabbitmq.client.Address; +import java.util.Arrays; import com.rabbitmq.client.impl.ConnectionParams; import com.rabbitmq.client.TopologyRecoveryException; @@ -174,6 +177,36 @@ public void testConnectionHangInNegotiation() { assertEquals("Wrong type of exception returned.", SocketTimeoutException.class, exceptionList.get(0).getClass()); } + public void testConnectionName() throws IOException, TimeoutException { + String connectionName = "custom name"; + Connection connection = factory.newConnection(connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + + List
addresses_list = Arrays.asList(new Address("127.0.0.1"), new Address("127.0.0.1", 5672)); + connection = factory.newConnection(addresses_list, connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + + Address[] addresses_arr = {new Address("127.0.0.1"), new Address("127.0.0.1", 5672)}; + connection = factory.newConnection(addresses_arr, connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + + ExecutorService executor = Executors.newSingleThreadExecutor(); + connection = factory.newConnection(executor, connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + + connection = factory.newConnection(executor, addresses_list, connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + + connection = factory.newConnection(executor, addresses_arr, connectionName); + assertEquals(connectionName, connection.getConnectionName()); + connection.close(); + } + /** Mock frame handler to facilitate testing. */ private static class MockFrameHandler implements FrameHandler { /** How many times has sendHeader() been called? */ diff --git a/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java b/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java index efb944a347..e80d5dbbbc 100644 --- a/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java +++ b/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java @@ -30,6 +30,21 @@ public void testConnectionRecovery() throws IOException, InterruptedException { assertTrue(connection.isOpen()); } + public void testNamedConnectionRecovery() + throws IOException, InterruptedException, TimeoutException { + String connectionName = "custom name"; + AutorecoveringConnection c = newRecoveringConnection(connectionName); + try { + assertTrue(c.isOpen()); + assertEquals(connectionName, c.getConnectionName()); + closeAndWaitForRecovery(c); + assertTrue(c.isOpen()); + assertEquals(connectionName, c.getConnectionName()); + } finally { + c.abort(); + } + } + public void testConnectionRecoveryWithServerRestart() throws IOException, InterruptedException { assertTrue(connection.isOpen()); restartPrimaryAndWaitForRecovery(); @@ -739,6 +754,17 @@ private AutorecoveringConnection newRecoveringConnection(List
addresses return newRecoveringConnection(false, addresses); } + private AutorecoveringConnection newRecoveringConnection(boolean disableTopologyRecovery, String connectionName) + throws IOException, TimeoutException { + ConnectionFactory cf = buildConnectionFactoryWithRecoveryEnabled(disableTopologyRecovery); + return (AutorecoveringConnection) cf.newConnection(connectionName); + } + + private AutorecoveringConnection newRecoveringConnection(String connectionName) + throws IOException, TimeoutException { + return newRecoveringConnection(false, connectionName); + } + private ConnectionFactory buildConnectionFactoryWithRecoveryEnabled(boolean disableTopologyRecovery) { ConnectionFactory cf = new ConnectionFactory(); cf.setNetworkRecoveryInterval(RECOVERY_INTERVAL); From 1835085a6af90728c0627a9f8722195c6a5302fe Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Mon, 18 Apr 2016 01:11:16 +0300 Subject: [PATCH 4/4] Naming, docs, cosmetics --- src/com/rabbitmq/client/Connection.java | 13 +++-- .../rabbitmq/client/ConnectionFactory.java | 52 ++++++++++++------- .../rabbitmq/client/impl/AMQConnection.java | 9 +--- .../recovery/AutorecoveringConnection.java | 10 ++-- .../client/test/AMQConnectionTest.java | 34 ++++++------ .../test/functional/ConnectionRecovery.java | 4 +- 6 files changed, 72 insertions(+), 50 deletions(-) diff --git a/src/com/rabbitmq/client/Connection.java b/src/com/rabbitmq/client/Connection.java index 95d6445f69..27d21d1f6a 100644 --- a/src/com/rabbitmq/client/Connection.java +++ b/src/com/rabbitmq/client/Connection.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.net.InetAddress; import java.util.Map; +import java.util.concurrent.ExecutorService; /** * Public API: Interface to an AMQ connection. See the see the spec for details. @@ -94,11 +95,17 @@ public interface Connection extends ShutdownNotifier { // rename to AMQPConnecti Map getClientProperties(); /** - * Get connection name client property value + * Returns client-provided connection name, if any. Note that the value + * returned does not uniquely identify a connection and cannot be used + * as a connection identifier in HTTP API requests. * - * @return string connection name from client properties, or null if there is not such property. + * + * + * @return client-provided connection name, if any + * @see ConnectionFactory#newConnection(Address[], String) + * @see ConnectionFactory#newConnection(ExecutorService, Address[], String) */ - String getConnectionName(); + String getClientProvidedName(); /** * Retrieve the server properties. diff --git a/src/com/rabbitmq/client/ConnectionFactory.java b/src/com/rabbitmq/client/ConnectionFactory.java index 3eb7645745..599de713c0 100644 --- a/src/com/rabbitmq/client/ConnectionFactory.java +++ b/src/com/rabbitmq/client/ConnectionFactory.java @@ -650,7 +650,7 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce /** - * Create a new broker connection, picking the first available address from + * Create a new broker connection with a client-provided name, picking the first available address from * the list. * * If automatic connection recovery @@ -658,12 +658,16 @@ public Connection newConnection(Address[] addrs) throws IOException, TimeoutExce * reconnection attempts will pick a random accessible address from the provided list. * * @param addrs an array of known broker addresses (hostname/port pairs) to try in order - * @param connectionName arbitrary sring for connection name client property + * @param clientProvidedName application-specific connection name, will be displayed + * in the management UI if RabbitMQ server supports it. + * This value doesn't have to be unique and cannot be used + * as a connection identifier e.g. in HTTP API requests. + * This value is supposed to be human-readable. * @return an interface to the connection * @throws IOException if it encounters a problem */ - public Connection newConnection(Address[] addrs, String connectionName) throws IOException, TimeoutException { - return newConnection(this.sharedExecutor, Arrays.asList(addrs), connectionName); + public Connection newConnection(Address[] addrs, String clientProvidedName) throws IOException, TimeoutException { + return newConnection(this.sharedExecutor, Arrays.asList(addrs), clientProvidedName); } /** @@ -683,7 +687,7 @@ public Connection newConnection(List
addrs) throws IOException, Timeout } /** - * Create a new broker connection, picking the first available address from + * Create a new broker connection with a client-provided name, picking the first available address from * the list. * * If automatic connection recovery @@ -691,12 +695,16 @@ public Connection newConnection(List
addrs) throws IOException, Timeout * reconnection attempts will pick a random accessible address from the provided list. * * @param addrs a List of known broker addresses (hostname/port pairs) to try in order - * @param connectionName arbitrary sring for connection name client property + * @param clientProvidedName application-specific connection name, will be displayed + * in the management UI if RabbitMQ server supports it. + * This value doesn't have to be unique and cannot be used + * as a connection identifier e.g. in HTTP API requests. + * This value is supposed to be human-readable. * @return an interface to the connection * @throws IOException if it encounters a problem */ - public Connection newConnection(List
addrs, String connectionName) throws IOException, TimeoutException { - return newConnection(this.sharedExecutor, addrs, connectionName); + public Connection newConnection(List
addrs, String clientProvidedName) throws IOException, TimeoutException { + return newConnection(this.sharedExecutor, addrs, clientProvidedName); } /** @@ -719,7 +727,7 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw /** - * Create a new broker connection, picking the first available address from + * Create a new broker connection with a client-provided name, picking the first available address from * the list. * * If automatic connection recovery @@ -728,13 +736,17 @@ public Connection newConnection(ExecutorService executor, Address[] addrs) throw * * @param executor thread execution service for consumers on the connection * @param addrs an array of known broker addresses (hostname/port pairs) to try in order - * @param connectionName arbitrary sring for connection name client property + * @param clientProvidedName application-specific connection name, will be displayed + * in the management UI if RabbitMQ server supports it. + * This value doesn't have to be unique and cannot be used + * as a connection identifier e.g. in HTTP API requests. + * This value is supposed to be human-readable. * @return an interface to the connection * @throws java.io.IOException if it encounters a problem * @see Automatic Recovery */ - public Connection newConnection(ExecutorService executor, Address[] addrs, String connectionName) throws IOException, TimeoutException { - return newConnection(executor, Arrays.asList(addrs), connectionName); + public Connection newConnection(ExecutorService executor, Address[] addrs, String clientProvidedName) throws IOException, TimeoutException { + return newConnection(executor, Arrays.asList(addrs), clientProvidedName); } /** @@ -756,7 +768,7 @@ public Connection newConnection(ExecutorService executor, List
addrs) t } /** - * Create a new broker connection, picking the first available address from + * Create a new broker connection with a client-provided name, picking the first available address from * the list. * * If automatic connection recovery @@ -765,20 +777,24 @@ public Connection newConnection(ExecutorService executor, List
addrs) t * * @param executor thread execution service for consumers on the connection * @param addrs a List of known broker addrs (hostname/port pairs) to try in order - * @param connectionName arbitrary sring for connection name client property + * @param clientProvidedName application-specific connection name, will be displayed + * in the management UI if RabbitMQ server supports it. + * This value doesn't have to be unique and cannot be used + * as a connection identifier e.g. in HTTP API requests. + * This value is supposed to be human-readable. * @return an interface to the connection * @throws java.io.IOException if it encounters a problem * @see Automatic Recovery */ - public Connection newConnection(ExecutorService executor, List
addrs, String connectionName) + public Connection newConnection(ExecutorService executor, List
addrs, String clientProvidedName) throws IOException, TimeoutException { // make sure we respect the provided thread factory FrameHandlerFactory fhFactory = createFrameHandlerFactory(); ConnectionParams params = params(executor); - // set connection name client property - if (connectionName != null) { + // set client-provided via a client property + if (clientProvidedName != null) { Map properties = new HashMap(params.getClientProperties()); - properties.put("connection_name", connectionName); + properties.put("connection_name", clientProvidedName); params.setClientProperties(properties); } diff --git a/src/com/rabbitmq/client/impl/AMQConnection.java b/src/com/rabbitmq/client/impl/AMQConnection.java index 3634165950..ee6b0054a7 100644 --- a/src/com/rabbitmq/client/impl/AMQConnection.java +++ b/src/com/rabbitmq/client/impl/AMQConnection.java @@ -470,13 +470,8 @@ public Map getClientProperties() { return new HashMap(_clientProperties); } - public String getConnectionName() { - Object connectionName = _clientProperties.get("connection_name"); - if (connectionName == null){ - return null; - } else { - return connectionName.toString(); - } + public String getClientProvidedName() { + return (String) _clientProperties.get("connection_name"); } /** diff --git a/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java b/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java index c7663d16b8..451d53308e 100644 --- a/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java +++ b/src/com/rabbitmq/client/impl/recovery/AutorecoveringConnection.java @@ -5,6 +5,7 @@ import com.rabbitmq.client.BlockedListener; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; import com.rabbitmq.client.MissedHeartbeatException; import com.rabbitmq.client.Recoverable; import com.rabbitmq.client.RecoveryListener; @@ -27,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; /** @@ -157,10 +159,12 @@ public Map getClientProperties() { } /** - * @see com.rabbitmq.client.Connection#getConnectionName() + * @see com.rabbitmq.client.Connection#getClientProvidedName() + * @see ConnectionFactory#newConnection(Address[], String) + * @see ConnectionFactory#newConnection(ExecutorService, Address[], String) */ - public String getConnectionName() { - return delegate.getConnectionName(); + public String getClientProvidedName() { + return delegate.getClientProvidedName(); } /** diff --git a/test/src/com/rabbitmq/client/test/AMQConnectionTest.java b/test/src/com/rabbitmq/client/test/AMQConnectionTest.java index db650404cb..a267661018 100644 --- a/test/src/com/rabbitmq/client/test/AMQConnectionTest.java +++ b/test/src/com/rabbitmq/client/test/AMQConnectionTest.java @@ -177,33 +177,33 @@ public void testConnectionHangInNegotiation() { assertEquals("Wrong type of exception returned.", SocketTimeoutException.class, exceptionList.get(0).getClass()); } - public void testConnectionName() throws IOException, TimeoutException { - String connectionName = "custom name"; - Connection connection = factory.newConnection(connectionName); - assertEquals(connectionName, connection.getConnectionName()); + public void testClientProvidedConnectionName() throws IOException, TimeoutException { + String providedName = "event consumers connection"; + Connection connection = factory.newConnection(providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); - List
addresses_list = Arrays.asList(new Address("127.0.0.1"), new Address("127.0.0.1", 5672)); - connection = factory.newConnection(addresses_list, connectionName); - assertEquals(connectionName, connection.getConnectionName()); + List
addrs1 = Arrays.asList(new Address("127.0.0.1"), new Address("127.0.0.1", 5672)); + connection = factory.newConnection(addrs1, providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); - Address[] addresses_arr = {new Address("127.0.0.1"), new Address("127.0.0.1", 5672)}; - connection = factory.newConnection(addresses_arr, connectionName); - assertEquals(connectionName, connection.getConnectionName()); + Address[] addrs2 = {new Address("127.0.0.1"), new Address("127.0.0.1", 5672)}; + connection = factory.newConnection(addrs2, providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); - ExecutorService executor = Executors.newSingleThreadExecutor(); - connection = factory.newConnection(executor, connectionName); - assertEquals(connectionName, connection.getConnectionName()); + ExecutorService xs = Executors.newSingleThreadExecutor(); + connection = factory.newConnection(xs, providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); - connection = factory.newConnection(executor, addresses_list, connectionName); - assertEquals(connectionName, connection.getConnectionName()); + connection = factory.newConnection(xs, addrs1, providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); - connection = factory.newConnection(executor, addresses_arr, connectionName); - assertEquals(connectionName, connection.getConnectionName()); + connection = factory.newConnection(xs, addrs2, providedName); + assertEquals(providedName, connection.getClientProvidedName()); connection.close(); } diff --git a/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java b/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java index e80d5dbbbc..471557a791 100644 --- a/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java +++ b/test/src/com/rabbitmq/client/test/functional/ConnectionRecovery.java @@ -36,10 +36,10 @@ public void testNamedConnectionRecovery() AutorecoveringConnection c = newRecoveringConnection(connectionName); try { assertTrue(c.isOpen()); - assertEquals(connectionName, c.getConnectionName()); + assertEquals(connectionName, c.getClientProvidedName()); closeAndWaitForRecovery(c); assertTrue(c.isOpen()); - assertEquals(connectionName, c.getConnectionName()); + assertEquals(connectionName, c.getClientProvidedName()); } finally { c.abort(); }