繁体   English   中英

是否可以在远程代理上获取队列列表?

[英]Is it possible to get a list of queues on a remote broker?

我正在试图找出如何获取远程代理上的现有队列列表。

看起来我可以通过添加咨询消息(我还没有工作)来创建/销毁它们来侦听队列,但我需要在启动时获得所有现有队列。

看起来我可以使用getDestinationMap来做到这一点:

http://activemq.apache.org/maven/apidocs/org/apache/activemq/broker/region/Region.html#getDestinationMap()

但这似乎只能从嵌入式和进程中的代理调用。

我的意思是......我愿意走这条路,但似乎更有意义的是为activemq设置正常的init / daemon,然后让远程进程像普通的JMS使用者一样连接到它。

该文档似乎暗示它是可能的:

http://activemq.apache.org/how-can-i-see-what-destinations-are-used.html

但这是通过使用Region对象,只有在与activemq位于同一JVM中时才有可能。

    // Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

// Create a Connection
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();


//Important point that was missed in the above answer
connection.start();

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

for(ActiveMQQueue queue : queues){
    try {
        System.out.println(queue.getQueueName());
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

请参阅此答案: https//stackoverflow.com/a/14021722/3735747

如果您在Java中执行此操作,则可以使用DestinationSource类: http//activemq.apache.org/maven/5.7.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html

创建连接并使用ActiveMQConnection类型而不是JMS连接类型。

// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

// Create a Connection
ActiveMQConnection connection = (ActiveMQConnection) connectionFactory.createConnection();

连接后,您可以创建DestinationSource对象并获取队列:

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

for(ActiveMQQueue queue : queues){
    try {
        System.out.println(queue.getQueueName());
    } catch (JMSException e) {
        e.printStackTrace();
    }
}

暂无
暂无

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

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