简体   繁体   中英

get all Queue from activeMQ

I am new to activeMQ . I need to write code to get all the Queues and read the messages. I did not find any API like get all Queues. How can I read the Queues from ActiveMQ .If possible some example will be helpful.

Get all Queues in ActiveMQ in java.

Add Below Maven dependencies in pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
    <version>4.3.2.RELEASE</version>
</dependency>  

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-spring</artifactId>
    <version>5.14.0</version>
</dependency>

You can change tcp://localhost:61616/ to tcp://180.50.50.10:61616/ where activemq service is running.

Java Code:

try {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616/");

    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();
    DestinationSource ds = connection.getDestinationSource();

    connection.start();

    Set<ActiveMQQueue> queues = ds.getQueues();

    for (ActiveMQQueue activeMQQueue : queues) {
        try {
            System.out.println(activeMQQueue.getQueueName());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
    connection.close();
} catch (Exception e) {
    e.printStackTrace();
}

Console Output:

HtmlQueue
emaildewsgmc
pdfdirectinpirepscli
pdfdirectinpirecli
InQueue
ReceiveQueue
NormalPriorityQueue
emaildirecthp
pdfdewsgmc
pdfdirecthp
Send2Recv
SaveQueue
LowPriorityQueue
emaildewshp
HighPriorityQueue
PdfQueue
AnotherDest
pdfdewshp
emaildirectgmc

Man You are already using a API named activeMQ and from this API You can get all the queues.
I am unable to understand your this part of question where you said
* I did not find any api like get Q*
Anyway you can use the JMX for this. The easiest way is to use JMX by pointing your JMX console or JConsole at the broker JVM.
programmatically You can also get all of the active destinations from the broker using Java code via getDestinations() . You can also get a Map of all the Destination objects indexed by ActiveMQDestination via getDestinationMap(). This allows you to look at the individual destination details such as the queue depths and so forth

The last way is to use the WebConsole . The ActiveMQ Web Console is a web based administration tool for working with ActiveMQ. When used with the JMX support it can be an invaluable tool for working with ActiveMQ.
Please follow the detailed support of ActiveMQ on their website where you can find almost everything :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM