Alvin’s Blog

November 25, 2011

ActiveMQ: Consumer

Filed under: ActiveMQ — amcbride @ 8:59 pm

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


namespace TestActiveMQ
{
    class Program
    {
        static void Main(string[] args)
        {
            IConnectionFactory factory = new ConnectionFactory("tcp://localhost:61616/");

            using (IConnection connection = factory.CreateConnection())
            {
                connection.ClientId = "MYID";
                connection.Start();

                using (ISession session = connection.CreateSession())
                {
                    IMessageConsumer consumer = session.CreateConsumer(new ActiveMQQueue("px_contracts_update"), null, false);
                    consumer.Listener += consumer_Listener;

                    Console.ReadLine();
                }

                connection.Stop();
            }
        }

        private static void consumer_Listener(IMessage message)
        {
            Console.WriteLine("Got: " + ((ITextMessage)message).Text);
        } 

    }
}

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.