activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zaeem <zaeems...@gmail.com>
Subject Re: How to find consumers on an exiting ActiveMQ Queue in c#
Date Wed, 26 Jul 2017 16:01:11 GMT

Below snippets lets you list Queues on the broker,Topics but i need
something similar to list consumers on Queues for that broker by just
passing a Queue Name.

        public const string QUEUE_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.Queue";
        public const string TOPIC_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.Topic";
        public const string TEMPQUEUE_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.TempQueue";
        public const string TEMPTOPIC_ADVISORY_DESTINATION =
"ActiveMQ.Advisory.TempTopic";

 private static void Enumerate(string destination, Action<DestinationInfo>
action)
        {
            IDestination dest = _session.GetTopic(destination);
            using (IMessageConsumer consumer =
_session.CreateConsumer(dest))
            {
                IMessage advisory;

                while ((advisory =
consumer.Receive(TimeSpan.FromMinutes(2000))) != null)
                {
                    ActiveMQMessage am = advisory as ActiveMQMessage;
                    if (am != null & am.DataStructure != null)
                    {
                        DestinationInfo info = am.DataStructure as
DestinationInfo;
                        if (info != null)
                        {
                            action(info);
                        }
                    }
                }
            }
        }

      

        public static void EnumerateQueues()
        {
            Console.WriteLine("Listing all Queues on Broker:");
            Enumerate(QUEUE_ADVISORY_DESTINATION, info =>
                Console.WriteLine("   Queue: " + info.Destination));
            Console.WriteLine("Listing Complete.");
        }

        public static void EnumerateTopics()
        {
            Console.WriteLine("Listing all Topics on Broker:");
            Enumerate(TOPIC_ADVISORY_DESTINATION, info =>
                Console.WriteLine("   Topic: " + info.Destination));
            Console.WriteLine("Listing Complete.");

        }

        public static void EnumerateDestinations()
        {
            Console.WriteLine("Listing all Destinations on Broker:");
            Enumerate(ALLDEST_ADVISORY_DESTINATION, info =>
            {
                string destType = info.Destination.IsTopic ? "Topic" :
"Qeue";
                destType = info.Destination.IsTemporary ? "Temporary" +
destType : destType;
                Console.WriteLine("   " + destType + ": " +
info.Destination);
            });
            Console.WriteLine("Listing Complete.");
        }



--
View this message in context: http://activemq.2283324.n4.nabble.com/How-to-find-consumers-on-an-existing-ActiveMQ-Queue-in-c-tp4728927p4728936.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message