Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get a list of queues on a remote broker?

Tags:

java

activemq

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.

like image 563
burtonator Avatar asked Jun 13 '14 19:06

burtonator


People also ask

How do I view ActiveMQ queue?

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):

Can a queue receive messages from many senders?

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.


1 Answers

    // 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();
    }
}
like image 79
Udara Seneviratne Avatar answered Oct 01 '22 17:10

Udara Seneviratne