activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: [NMS] Listing Queues mabe its time to NMX
Date Tue, 14 Dec 2010 20:09:02 GMT
On Tue, 2010-12-14 at 11:11 -0800, gabriel.mancini wrote:
> Hi Tim,
> 
>   So,I Just need get the list names of queues in C#
> 
> 


Here us a quick and dirty sample I just created to show you how its
basically done.

using System;
using Apache.NMS;
using Apache.NMS.Util;
using Apache.NMS.ActiveMQ;
using Apache.NMS.ActiveMQ.Commands;

namespace AdvisoryExample
{
    class AdvisoryExample
    {
        private IConnection connection;
        private ISession session;

        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";

        public const String ALLDEST_ADVISORY_DESTINATION =
QUEUE_ADVISORY_DESTINATION + "," +

TOPIC_ADVISORY_DESTINATION + "," +

TEMPQUEUE_ADVISORY_DESTINATION + "," +

TEMPTOPIC_ADVISORY_DESTINATION;

        AdvisoryExample()
        {
            IConnectionFactory factory = new ConnectionFactory();

            connection = factory.CreateConnection();
            connection.Start();
            session = connection.CreateSession();
        }

        void EnumerateQueues()
        {
            Console.WriteLine("Listing all Queues on Broker:");

            IDestination dest =
session.GetTopic(QUEUE_ADVISORY_DESTINATION);

            using(IMessageConsumer consumer =
session.CreateConsumer(dest))
            {
                IMessage advisory;

                while((advisory =
consumer.Receive(TimeSpan.FromMilliseconds(2000))) != 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.");
        }

        void EnumerateTopics()
        {
            Console.WriteLine("Listing all Topics on Broker:");

            IDestination dest =
session.GetTopic(TOPIC_ADVISORY_DESTINATION);

            using(IMessageConsumer consumer =
session.CreateConsumer(dest))
            {
                IMessage advisory;

                while((advisory =
consumer.Receive(TimeSpan.FromMilliseconds(2000))) != null)
                {
                    ActiveMQMessage amqMsg = advisory as
ActiveMQMessage;

                    if(amqMsg.DataStructure != null)
                    {
                        DestinationInfo info = amqMsg.DataStructure as
DestinationInfo;
                        if(info != null)
                        {
                            Console.WriteLine("   Topic: " +
info.Destination.ToString() );
                        }
                    }
                }
            }
            Console.WriteLine("Listing Complete.");
        }

        void EnumerateDestinations()
        {
            Console.WriteLine("Listing all Destinations on Broker:");

            IDestination dest =
session.GetTopic(ALLDEST_ADVISORY_DESTINATION);

            using(IMessageConsumer consumer =
session.CreateConsumer(dest))
            {
                IMessage advisory;

                while((advisory =
consumer.Receive(TimeSpan.FromMilliseconds(2000))) != null)
                {
                    ActiveMQMessage amqMsg = advisory as
ActiveMQMessage;

                    if(amqMsg.DataStructure != null)
                    {
                        DestinationInfo info = amqMsg.DataStructure as
DestinationInfo;
                        if(info != null)
                        {
                            string destType = info.Destination.IsTopic ?
"Topic" : "Qeue";
                            destType = info.Destination.IsTemporary ?
"Temporary" + destType : destType;
                            Console.WriteLine("   " + destType + ": " +
info.Destination.ToString() );
                        }
                    }
                }
            }
            Console.WriteLine("Listing Complete.");
        }

        void ShutDown()
        {
            session.Close();
            connection.Close();
        }

        public static void Main (string[] args)
        {
            AdvisoryExample ex = new AdvisoryExample();

            ex.EnumerateQueues();
            ex.EnumerateTopics();
            ex.EnumerateDestinations();
            ex.ShutDown();
        }
    }
}


Regards

-- 
Tim Bish
------------
FuseSource
Email: tim.bish@fusesource.com
Web: http://fusesource.com
Twitter: tabish121
Blog: http://timbish.blogspot.com/



Mime
View raw message