【问题标题】:Activemq list of queues nms .NETActivemq 队列列表 nms .NET
【发布时间】:2015-07-05 13:20:54
【问题描述】:

如何使用 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 有类似的方法吗?

谢谢。

【问题讨论】:

    标签: .net activemq nms


    【解决方案1】:

    选项 1:

    在 java 中,您会使用 JMX(我猜),但您可以使用 jolokia endpoint 通过 HTTP/JSON 访问 JMX 接口。

    例如,如果您通过此 URL(受密码保护)访问经纪人信息:http://&lt;hostname&gt;: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 的咨询主题。

    当您开始订阅时,您将获得一个包含队列的列表(每个队列一条消息)。添加新队列时,您将收到新消息。这很方便。

    【讨论】:

    • 我不知道 NMS 中有这样的功能。以上是我所知道的两种解决方案。
    • DestinationSource 位只是订阅咨询消息,因此滚动您自己的侦听器几乎可以完成同样的事情。您可以查看来自 activemq-client 的 Java 代码,并了解目标源代码是如何实现的。
    猜你喜欢
    • 2012-03-10
    • 2013-08-31
    • 2012-12-10
    • 2018-02-20
    • 2011-11-22
    • 1970-01-01
    • 2021-03-08
    • 2013-03-01
    • 1970-01-01
    相关资源
    最近更新 更多