2012-12-18 74 views
1

我是activeMQ的新用户。我需要编写代码来获取所有队列并阅读消息。 我没有找到像获取所有队列的API。 如何从ActiveMQ中读取队列。如果可能,有些示例会有所帮助。从activeMQ获取所有队列

+0

你在使用? Native API? JMS绑定? JEE MDB? –

回答

1

Man您已经使用了一个名为activeMQ的API,并从此API可以获取所有队列。
我不明白你说的这部分问题你说的
*我没有找到任何API喜欢得到Q *
无论如何,你可以使用JMX为此。 最简单的方法是通过将JMX控制台或JConsole指向代理JVM来使用JMX。
以编程方式您还可以通过getDestinations()使用Java代码获取代理中的所有活动目标。 您还可以通过getDestinationMap()获取由ActiveMQDestination索引的所有Destination对象的Map。这允许您查看各个目标详细信息,例如队列深度等

最后一种方法是使用WebConsole ActiveMQ Web控制台是一个基于Web的管理工具,用于处理ActiveMQ。当与JMX支持一起使用时,它可以成为使用ActiveMQ的宝贵工具。
请按照detailed support of ActiveMQ on their website where you can find almost everything :)

+1

我试过getDestinations和getDestinationMap,但getDestinations返回了空白数组和getDestinationMap找不到。你能给我一些代码库吗?像什么应该是网址(imean http:// localgost:8082或tcp:// localhost:616161)请让我知道。谢谢 – Anandkumar

+0

也许在代理上没有定义队列,请尝试调用createQueue(),然后调用getDestinations() – crowne

2

在java中获取ActiveMQ中的所有队列。

下面添加Maven依赖于的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> 

您可以更改TCP://本地主机:61616/TCP://180.50.50.10:61616/其中的ActiveMQ服务在跑。

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(); 
} 

控制台输出:

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