You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Matthew Xie <an...@163.com> on 2006/07/28 09:34:33 UTC

problem with openwire dotnet

I am using asynchronous approach to consume message by amq dotnet api.
the problem is that if i send serval messages to the amq server then i start
asynchronous approach consumer code to listen the message, but unexpectly i
found that nothing recieve. but if i send a message again then all the
messages are recieved include the lastest message.

here's the my test code:
        public void recieve(String queueName)
        {
            using (IConnection connection = factory.CreateConnection())
            {
                AcknowledgementMode acknowledgementMode =
AcknowledgementMode.ClientAcknowledge;
                ISession session =
connection.CreateSession(acknowledgementMode);

                IDestination destination = session.GetQueue(queueName);

                // lets create a consumer and producer
                IMessageConsumer consumer =
session.CreateConsumer(destination);
                
                //recieve the old message
//                IMessage message =
consumer.Receive(TimeSpan.FromMilliseconds(200));

                received = false;
                consumer.Listener += new MessageListener(OnMessage);

                Console.WriteLine("Start to listen messengers(program will
be exited upon received messenger)");
                WaitForMessageToArrive();

            }
        }

        protected void OnMessage(IMessage message)
        {
            ActiveMQTextMessage textmessage = (ActiveMQTextMessage)message;
            Console.WriteLine("Received message with ID:   {0}",
textmessage.NMSMessageId);
            String text = HttpUtility.UrlDecode(textmessage.Text);
            Console.WriteLine("Received message with text: " + text);

            message.Acknowledge();

            lock (semaphore)
            {
                received = true;
                Monitor.PulseAll(semaphore);
            }

        }

is there anything incrroect?
could someone do me a favor?
thanks!

matt
-- 
View this message in context: http://www.nabble.com/problem-with-openwire-dotnet-tf2013952.html#a5534983
Sent from the ActiveMQ - User forum at Nabble.com.


Re: problem with openwire dotnet

Posted by James Strachan <ja...@gmail.com>.
FWIW have you tried the latest code in SVN as we've applied a few
patches to the C# code recently.

Incidentally in JMS you are only meant to use a synchronous consumer
or an asynchornous consumer and not mix them. (e.g. its an error and
you get an exception if you try set a listener on a synchronous
consumer - it might be worth doing the same in C#)

Have you tried using just one or the other?


On 7/28/06, Matthew Xie <an...@163.com> wrote:
>
> I am using asynchronous approach to consume message by amq dotnet api.
> the problem is that if i send serval messages to the amq server then i start
> asynchronous approach consumer code to listen the message, but unexpectly i
> found that nothing recieve. but if i send a message again then all the
> messages are recieved include the lastest message.
>
> here's the my test code:
>         public void recieve(String queueName)
>         {
>             using (IConnection connection = factory.CreateConnection())
>             {
>                 AcknowledgementMode acknowledgementMode =
> AcknowledgementMode.ClientAcknowledge;
>                 ISession session =
> connection.CreateSession(acknowledgementMode);
>
>                 IDestination destination = session.GetQueue(queueName);
>
>                 // lets create a consumer and producer
>                 IMessageConsumer consumer =
> session.CreateConsumer(destination);
>
>                 //recieve the old message
> //                IMessage message =
> consumer.Receive(TimeSpan.FromMilliseconds(200));
>
>                 received = false;
>                 consumer.Listener += new MessageListener(OnMessage);
>
>                 Console.WriteLine("Start to listen messengers(program will
> be exited upon received messenger)");
>                 WaitForMessageToArrive();
>
>             }
>         }
>
>         protected void OnMessage(IMessage message)
>         {
>             ActiveMQTextMessage textmessage = (ActiveMQTextMessage)message;
>             Console.WriteLine("Received message with ID:   {0}",
> textmessage.NMSMessageId);
>             String text = HttpUtility.UrlDecode(textmessage.Text);
>             Console.WriteLine("Received message with text: " + text);
>
>             message.Acknowledge();
>
>             lock (semaphore)
>             {
>                 received = true;
>                 Monitor.PulseAll(semaphore);
>             }
>
>         }
>
> is there anything incrroect?
> could someone do me a favor?
> thanks!
>
> matt
> --
> View this message in context: http://www.nabble.com/problem-with-openwire-dotnet-tf2013952.html#a5534983
> Sent from the ActiveMQ - User forum at Nabble.com.
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/