diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java index 8807b8a83f..ebce559ac5 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -1214,6 +1214,23 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon return brokerInfo.getBrokerId().getValue(); } + /** + * Returns the broker name if one is available or null if one is not available yet. + */ + public String getBrokerName() { + if (brokerInfo == null) { + return null; + } + return brokerInfo.getBrokerName(); + } + + /** + * Returns the broker information if it is available or null if it is not available yet. + */ + public BrokerInfo getBrokerInfo() { + return brokerInfo; + } + /** * @return Returns the RedeliveryPolicy. * @throws JMSException diff --git a/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java b/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java index 1674e88a4f..a4ee51b1f3 100755 --- a/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java @@ -60,6 +60,18 @@ public class ActiveMQConnectionFactoryTest extends CombinationTestSupport { assertNull( BrokerRegistry.getInstance().lookup("localhost") ); } + public void testGetBrokerName() throws URISyntaxException, JMSException { + ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); + ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection(); + connection.start(); + + String brokerName = connection.getBrokerName(); + System.out.println("Got broker name: " + brokerName); + + assertNotNull("No broker name available!", brokerName); + connection.close(); + } + public void testCreateTcpConnectionUsingAllocatedPort() throws Exception { assertCreateConnection("tcp://localhost:0?wireFormat.tcpNoDelayEnabled=true"); }