activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Xie <ant_mira...@163.com>
Subject Re: Message recieved but can't removed from the amq server problem
Date Thu, 20 Jul 2006 06:39:16 GMT

following is the my test code.
after run the test, a problem found that the message recieved successfully,
but while monitor the mq server that the this message still in the mq
server. if you run a simple consumer test, the message could be recieved
agian.

   public class AsyncConsumer
    {
        IConnectionFactory factory;
        protected object semaphore = new object();
        protected bool received;
        protected int receiveTimeout = 1000;


        public AsyncConsumer()
        {
            Uri uri = new Uri("tcp://localhost:61616");
            factory = new ConnectionFactory(uri);
        }

        public void textMessageSRExample()
        {
            using (IConnection connection = factory.CreateConnection())
            {
                AcknowledgementMode acknowledgementMode =
AcknowledgementMode.AutoAcknowledge;
                ISession session =
connection.CreateSession(acknowledgementMode);

                IDestination destination = session.GetQueue("FOO.BAR");

                // lets create a consumer and producer
                IMessageConsumer consumer =
session.CreateConsumer(destination);
                consumer.Listener += new MessageListener(OnMessage);

                IMessageProducer producer =
session.CreateProducer(destination);
                producer.Persistent = true;

                // lets send a message
                ITextMessage request = session.CreateTextMessage("Hello
World!");
                request.NMSCorrelationID = "abc";
                request.Properties["JMSXGroupID"] = "cheese";
                request.Properties["myHeader"] = "James";

                producer.Send(request);

                WaitForMessageToArrive();


            }
        }

        protected void OnMessage(IMessage message)
        {
            ActiveMQTextMessage textmessage = (ActiveMQTextMessage) message;
            Console.WriteLine("Received message with ID:   " +
textmessage.NMSMessageId);
            Console.WriteLine("Received message with text: " +
textmessage.Text);
            lock (semaphore)
            {
                received = true;
                Monitor.PulseAll(semaphore);
            }

        }

        protected void WaitForMessageToArrive()
        {
            lock (semaphore)
            {
                if (!received)
                {
                    Monitor.Wait(semaphore, receiveTimeout);
                }
            }
        }

    }
-- 
View this message in context: http://www.nabble.com/Message-recieved-but-can%27t-removed-from-the-amq-server-problem-tf1964193.html#a5409632
Sent from the ActiveMQ - User forum at Nabble.com.


Mime
View raw message