是否可以在远程代理上获取队列列表? [英] Is it possible to get a list of queues on a remote broker?

查看:99
本文介绍了是否可以在远程代理上获取队列列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to figure out how to get a list of existing queues on a remote broker.

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

It looks like I can listen to queues as they are created/destroyed by adding an advisory message (which I don't yet have working) but I need to get all EXISTING queues on startup.

看起来我可以这样做使用getDestinationMap:

It looks like I can do this with getDestinationMap:

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

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

But that seems like it can only be called from an embedded and in-process broker.

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

I mean... I'm willing to go that route but it seems to make more sense to just have the normal init/daemon setup for activemq and then have a remote process connect to it like a normal JMS consumer.

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

This documentation seems to imply that it's possible:

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

但这是通过使用Region对象而且只有在你看来才有可能与activemq在同一个JVM中。

But that's by using a Region object and that only seems possible if you're in the same JVM as activemq.

推荐答案

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

这篇关于是否可以在远程代理上获取队列列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆