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:
http://activemq.apache.org/maven/apidocs/org/apache/activemq/broker/region/Region.html#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.
You can also browse the contents of a queue using the JMS QueueBrowser. Through the MBeans, you can monitor individual destinations including message statistics related to the destination. For example, you'll see the following attributes on a destination (Queue or Topic):
A queue is a destination to which producers send messages and a source from which receivers consume messages. Each message is delivered to only one receiver. Multiple receivers may listen on a queue, but each message in the queue may only be consumed by one of the queue's receivers.
// 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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With