获取ActiveMQ中的队列名称列表

问题描述 投票:1回答:2

我试过下面的代码来获取ActiveMQ中的队列列表。但它不起作用。我的ActiveMQ中有4个队列。

try {
ActiveMQConnection.makeConnection(URL).start();
Set<ActiveMQQueue> allque= ActiveMQConnection.makeConnection().getDestinationSource().getQueues();

Iterator<ActiveMQQueue> itr= allque.iterator();
while(itr.hasNext()){
ActiveMQQueue q= itr.next();
System.out.println(q.getQueueName());
}
} catch (Exception e) {

e.printStackTrace();
}

请让我知道我的代码中的任何更正或一些新代码完成它。

java activemq
2个回答
2
投票

目标源功能不是在Broker上查找目标的保证方法。在许多情况下,该功能可能无法提供任何结果,例如,当Broker上的顾问功能被禁用或客户端已配置为不查看建议时。您还可以立即查询目标,这不一定允许从Broker将顾问分派到客户端所需的时间。

更可靠的机制是Broker上的JMX support,它提供了获取目的地列表的方法以及有关正在运行的代理实例的大量其他信息。

有很多articles在那里展示如何使用JMX与ActiveMQ。


0
投票

你必须在同一个连接上调用getDestinationSource()。getQueues()

try {
    ActiveMQConnection conn = ActiveMQConnection.makeConnection(URL);
    conn.start();

    Set<ActiveMQQueue> allque= conn.getDestinationSource().getQueues();
    Iterator<ActiveMQQueue> itr= allque.iterator();
    while(itr.hasNext()){
      ActiveMQQueue q= itr.next();
      System.out.println(q.getQueueName());
    }
} catch (Exception e) {

e.printStackTrace();
}
© www.soinside.com 2019 - 2024. All rights reserved.