activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd <>
Subject NMS Consumer Not Receiving Messages
Date Mon, 12 Sep 2011 22:10:40 GMT
I've poked around a bit and haven't found anything in the forum or docs.

I created what is supposed to be an asynchronous consumer. I found some code
in the NMS docs that I adapted. See below. (You can ignore the XML
deserialization stuff.)

This worked once or twice, but I cannot get it to work anymore. What might
be wrong with this code?

Thanks for your help.


using System;
using Apache.NMS;
using Apache.NMS.Util;
using model;
using System.Xml.Serialization;
using System.IO;
using Domain.util;

namespace Service.AuditTrail
    class AuditTrailService
        private IConnectionFactory factory;
        private string receiveQueueName;
        IConnection connection;
        ISession session;
        IDestination destination;
        IMessageConsumer consumer;

        private AuditTrailService(string hostUri, string receiveQueue)
            Uri uri = new Uri(hostUri);
            factory = new NMSConnectionFactory(uri);
            receiveQueueName = receiveQueue;

        private void Start()
            Console.WriteLine("Starting AuditTrailService");

        #region Helper Methods
        private void SetupQueueListener()
            using (IConnection connection = factory.CreateConnection())
            using (ISession session = connection.CreateSession())
                IDestination destination =
SessionUtil.GetDestination(session, receiveQueueName);

                using (IMessageConsumer consumer =
                    consumer.Listener += new

        private void OnMessageReceived(IMessage receivedMessage)
            Console.WriteLine("Audit Trail Service message received...");
            ITextMessage textMessage = receivedMessage as ITextMessage;

            if (textMessage != null)
                message message = ParseMessageText(textMessage.Text);
                AuditRecordManager manager = new AuditRecordManager();

                Console.Error.WriteLine("The received message was not an

        private static message ParseMessageText(string text)
            XmlSerializer ser = new XmlSerializer(typeof(message));
            StringReader reader = new StringReader(text);
            return (message)ser.Deserialize(reader);

        #region Main Method
        static void Main(string[] args)
            AuditTrailService service = new

            Console.WriteLine("Press enter to terminate service.");

View this message in context:
Sent from the ActiveMQ - User mailing list archive at

View raw message