如何使用ActiveMQ NMS ( .NET )获取队列和主题列表。用JAVA获取列表很简单。但是.NET呢?
在java中,我使用了以下方法:
String messageBrokerUrl = "tcp://localhost:61616";
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
"admin", "admin", messageBrokerUrl);
ActiveMQConnection connection;
connection = (ActiveMQConnection) connectionFactory
.createConnection();
connection.start();
this.session = connection.createSession(this.transacted, ackMode);
DestinationSource ds = connection.getDestinationSource();
Set<ActiveMQQueue> queues = ds.getQueues();
for (ActiveMQQueue activeMQQueue : queues) {
System.out.println(activeMQQueue.getQueueName());
}对于.NET有类似的方法吗?
谢谢。
发布于 2015-04-28 04:53:33
选项1:
在java中,您将使用JMX (我猜),但是您可以使用jolokia端点通过HTTP/JSON访问JMX接口。
例如,如果您通过以下URL访问代理信息(密码受保护):http://<hostname>:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost
您应该能够从JSON信息中解析队列。
答覆与此类似:
{
"request": {
"mbean": "org.apache.activemq:brokerName=localhost,type=Broker",
"type": "read"
},
"status": 200,
...
"value": {
"BrokerId": ....
"Queues": [
{
"objectName": "org.apache.activemq:brokerName=localhost,destinationName=QUEUE.1,destinationType=Queue,type=Broker"
},
{
"objectName": "org.apache.activemq:brokerName=localhost,destinationName=ANOTHER.QUEUE,destinationType=Queue,type=Broker"
},
{
"objectName": "org.apache.activemq:brokerName=localhost,destinationName=ActiveMQ.DLQ,destinationType=Queue,type=Broker"
},
{
"objectName": "org.apache.activemq:brokerName=localhost,destinationName=FOO.BAR,destinationType=Queue,type=Broker"
}
],
...
}
}备选方案2:
如果您想坚持使用纯NMS,您可以订阅一个名为ActiveMQ.Advisory.Queue的咨询主题。
当您开始订阅时,您将查看一个包含队列的列表(每个队列一条消息)。添加新队列时,您将收到新消息。这样很方便。
https://stackoverflow.com/questions/29889813
复制相似问题