[英]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.