Yes. I tried that but still unable to get message. Here's the code I tried.

using System;
using System.Threading;
using Apache.NMS;
using Apache.NMS.Util;

namespace Apache.NMS.ActiveMQ.Test
{
    public class TestMain
    {
        protected static AutoResetEvent semaphore = new
AutoResetEvent(false);
        protected static IMapMessage message = null;
        protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);

        public static void Main(string[] args)
        {
            Uri connecturi = new Uri("activemq:tcp://localhost:61616");

            Console.WriteLine("About to connect to " + connecturi);

            IConnectionFactory factory = new
NMSConnectionFactory(connecturi);

            using (IConnection connection = factory.CreateConnection())
            using (ISession session = connection.CreateSession())
            {
                IDestination destination =
SessionUtil.GetDestination(session, "topic://myTopic");
                Console.WriteLine("Using destination: " + destination);

                using (IMessageConsumer consumer =
session.CreateConsumer(destination))
                {
                    connection.Start();
                    consumer.Listener += new MessageListener(OnMessage);
                    semaphore.WaitOne((int)receiveTimeout.TotalMilliseconds,
true);

                    if (message == null)
                        Console.WriteLine("No message received!");
                    else
                    {
                        Console.WriteLine("Received message with ID:   " +
message.NMSMessageId);
                        Console.WriteLine("Received message:   " +
message.Body.GetString("myKey"));
                    }
                }
            }
        }

        protected static void OnMessage(IMessage receivedMsg)
        {
            message = receivedMsg as IMapMessage;
            semaphore.Set();
        }
    }
}

Is there any setting that I am suppose to do in schema file of ActiveMQ?



--
View this message in context: 
http://activemq.2283324.n4.nabble.com/strange-error-when-consume-message-from-queue-topic-tp4677680p4677850.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to