Reputation: 443
I'm trying to figure out how to get a list of existing queues on a remote broker.
It looks like I can listen to queues as they are created/destroyed by adding an advisory message (which I don't yet have working) but I need to get all EXISTING queues on startup.
It looks like I can do this with getDestinationMap:
But that seems like it can only be called from an embedded and in-process broker.
I mean... I'm willing to go that route but it seems to make more sense to just have the normal init/daemon setup for activemq and then have a remote process connect to it like a normal JMS consumer.
This documentation seems to imply that it's possible:
http://activemq.apache.org/how-can-i-see-what-destinations-are-used.html
But that's by using a Region object and that only seems possible if you're in the same JVM as activemq.
Upvotes: 6
Views: 7959
Reputation: 2483
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Create a Connection
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
//Important point that was missed in the above answer
connection.start();
DestinationSource ds = connection.getDestinationSource();
Set<ActiveMQQueue> queues = ds.getQueues();
for(ActiveMQQueue queue : queues){
try {
System.out.println(queue.getQueueName());
} catch (JMSException e) {
e.printStackTrace();
}
}
Upvotes: 9
Reputation: 421
See this answer: https://stackoverflow.com/a/14021722/3735747
If you're doing this in Java, there's the DestinationSource class that will help: http://activemq.apache.org/maven/5.7.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html
Create a connection and use the ActiveMQConnection type instead of the JMS Connection type.
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
// Create a Connection
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
Once you're connected, you can create a DestinationSource object and get the queues:
DestinationSource ds = connection.getDestinationSource();
Set<ActiveMQQueue> queues = ds.getQueues();
for(ActiveMQQueue queue : queues){
try {
System.out.println(queue.getQueueName());
} catch (JMSException e) {
e.printStackTrace();
}
}
Upvotes: 2