Dixit Gokhale
Dixit Gokhale

Reputation: 671

Activemq list of queues nms .NET

How do I get list of queues and topics using ActiveMQ NMS ( .NET ). Getting the list in JAVA is simple. But what about .NET.

In java I used this:

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

Is there a similar way for .NET?

Thanks.

Upvotes: 1

Views: 1352

Answers (1)

Petter Nordlander
Petter Nordlander

Reputation: 22279

Option 1:

In java, you would use JMX (I guess), but you can access the JMX interface via HTTP/JSON using the jolokia endpoint.

For instance, if you access the broker info via this URL (password protected): http://<hostname>:8161/api/jolokia/read/org.apache.activemq:type=Broker,brokerName=localhost

You should be able to parse the queues from the JSON info.

The reply is similar to this:

{
    "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"
            }
        ],
        ...
    }
}

Option 2:

If you want to stick with pure NMS, you can subscribe to an advisory topic called ActiveMQ.Advisory.Queue.

When you start subscribe, you will ge a list with queues (one message per queue). When new queues are added, you will get new messages. This can be convenient.

Upvotes: 3

Related Questions