get all Queue from activeMQ

梦想与她 提交于 2019-12-08 03:17:08

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/13927708/get-all-queue-from-activemq

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!