1

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.

Dixit Gokhale
  • 601
  • 1
  • 12
  • 32

1 Answers1

3

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.

Petter Nordlander
  • 22,053
  • 5
  • 50
  • 84
  • I am not aware such a feature in NMS. The above are the two solutions I know of. – Petter Nordlander Apr 28 '15 at 07:17
  • 1
    The DestinationSource bits simply subscribe to advisory messages so rolling your own listener does pretty much the same thing. You can look at the Java code from activemq-client and see how the destination source bits do it. – Tim Bish Apr 28 '15 at 13:33