简体   繁体   English

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

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

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

It looks like I can do this with getDestinationMap: 看起来我可以使用getDestinationMap来做到这一点:

http://activemq.apache.org/maven/apidocs/org/apache/activemq/broker/region/Region.html#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. 但这似乎只能从嵌入式和进程中的代理调用。

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

This documentation seems to imply that it's possible: 该文档似乎暗示它是可能的:

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

But that's by using a Region object and that only seems possible if you're in the same JVM as activemq. 但这是通过使用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();
    }
}

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

If you're doing this in Java, there's the DestinationSource class that will help: http://activemq.apache.org/maven/5.7.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html 如果您在Java中执行此操作,则可以使用DestinationSource类: http//activemq.apache.org/maven/5.7.0/activemq-core/apidocs/org/apache/activemq/advisory/DestinationSource.html

Create a connection and use the ActiveMQConnection type instead of the JMS Connection type. 创建连接并使用ActiveMQConnection类型而不是JMS连接类型。

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

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

Once you're connected, you can create a DestinationSource object and get the queues: 连接后,您可以创建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.

相关问题 我如何获取包含远程Websphere应用程序服务器中所有队列名称的列表? - How i can get list with names of all queues in remote websphere application server? 通过连接到代理,activeMQ队列变慢了吗? - activeMQ queues slowed down by connection to broker? 是否只能获取本地队列和别名队列的队列名称? - Is it possible to get only the queue names of local and alias queues? 如何以客户端的身份获取Stomp队列或主题列表(名称)? - How to get a list of Stomp queues or/and topics (their names) as a client? Spring 4 WebSocket远程代理配置 - Spring 4 WebSocket Remote Broker configuration ActiveMQ:如何在使用临时队列时处理代理故障转移 - ActiveMQ: How to handle broker failovers while using temporary queues 远程 Kafka 连接问题 - 代理可能不可用 - Remote Kafka Connection Issues - Broker may not be available 列出队列管理器上的所有队列 - List all queues on a queue manager 如何从Weblogic的jms模块的资源摘要表中获取jms队列列表? - How to get the list of jms queues from Summary of Resources table of jms module in weblogic? 如何从Weblogic的资源摘要表中获取特定集群的JMS队列列表? - How to get the list of jms queues from Summary of Resources table in weblogic for a certain cluster?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM