简体   繁体   English

从activeMQ获取所有队列

[英]get all Queue from activeMQ

I am new to activeMQ . 我是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. 我没有找到任何获得所有队列的API。 How can I read the Queues from ActiveMQ .If possible some example will be helpful. 我如何从ActiveMQ中读取队列。如果可能,一些示例会有所帮助。

Get all Queues in ActiveMQ in java. 在Java中获取ActiveMQ中的所有队列。

Add Below Maven dependencies in pom.xml pom.xml中添加以下Maven依赖项

<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. 您可以将tcp:// localhost:61616 /更改为运行activemq服务的tcp://180.50.50.10:61616 /

Java Code: Java代码:

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. 您已经在使用一个名为activeMQ的API,并且可以从该API获取所有队列。
I am unable to understand your this part of question where you said 我无法理解您所说的问题的这一部分
* I did not find any api like get Q* *我没有找到获得Q *的任何API *
Anyway you can use the JMX for this. 无论如何,您都可以使用JMX The easiest way is to use JMX by pointing your JMX console or JConsole at the broker JVM. 最简单的方法是通过将JMX控制台或JConsole指向代理JVM来使用JMX。
programmatically You can also get all of the active destinations from the broker using Java code via getDestinations() . 通过编程,您还可以使用Java代码通过getDestinations()从代理获取所有活动目标。 You can also get a Map of all the Destination objects indexed by ActiveMQDestination via getDestinationMap(). 您还可以通过getDestinationMap()获得由ActiveMQDestination索引的所有Destination对象的Map。 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 . 最后一种方法是使用WebConsole The ActiveMQ Web Console is a web based administration tool for working with ActiveMQ. ActiveMQ Web控制台是用于与ActiveMQ一起使用的基于Web的管理工具。 When used with the JMX support it can be an invaluable tool for working with ActiveMQ. 与JMX支持一起使用时,它可能是与ActiveMQ一起使用的宝贵工具。
Please follow the detailed support of ActiveMQ on their website where you can find almost everything :) 在其网站上关注ActiveMQ详细支持,您可以在其中找到几乎所有内容 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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