Reputation: 108
Is there a way to list out all the active queues in ActiveMQ. I am using Apache.NMS for communicating with ActiveMQ from C#.
I am not seeing any direct methods in the library.
Upvotes: 1
Views: 1862
Reputation: 1087
Please try this.
public void Test(ISession Session)
{
String QUEUE_ADVISORY_DESTINATION = "ActiveMQ.Advisory.Queue";
IDestination dest = Session.GetTopic(QUEUE_ADVISORY_DESTINATION);
using (IMessageConsumer consumer = Session.CreateConsumer(dest))
{
IMessage advisory;
while ((advisory = consumer.Receive()) != null)
{
ActiveMQMessage amqMsg = advisory as ActiveMQMessage;
if (amqMsg.DataStructure != null)
{
DestinationInfo info = amqMsg.DataStructure as DestinationInfo;
if (info != null)
{
Console.WriteLine(" Queue: " + info.Destination.ToString());
}
}
}
}
Console.WriteLine("Listing Complete.");
}
This is not a guaranteed way of listing queues. Please see this answer.
Upvotes: 3
Reputation: 51
Solution above contains one defect. If you will try to get message like this:
consumer.Receive()
you will wait infinitely long time while new event won't be occurred with queues information into ActiveMQ.
I recommend to set timeout:
consumer.Receive(TimeSpan.FromMilliseconds(2000))
and see example offitial site
Upvotes: 4