You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by dandandan <da...@jpmorgan.com> on 2009/09/30 19:08:46 UTC
Setting up a C# ActiveMQ listener
Hi,
This is most likely a very basic question so apologies in advance.
The Asynchrous Message Consumer example as show in
http://activemq.apache.org/nms/examples.html consumes one message only but
how do i set up the class to listen indefintely for messages on a particular
queue ie.process a message and carry on listening?
Thanks in advance
Dan
--
View this message in context: http://www.nabble.com/Setting-up-a-C--ActiveMQ-listener-tp25685236p25685236.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
Re: Setting up a C# ActiveMQ listener
Posted by Timothy Bish <ta...@gmail.com>.
On Wed, 2009-09-30 at 10:08 -0700, dandandan wrote:
> Hi,
>
> This is most likely a very basic question so apologies in advance.
>
> The Asynchrous Message Consumer example as show in
> http://activemq.apache.org/nms/examples.html consumes one message only but
> how do i set up the class to listen indefintely for messages on a particular
> queue ie.process a message and carry on listening?
>
> Thanks in advance
> Dan
The Asynchronous consumption example on that page shows you how to do
that particular task, and while it exits after receiving one message
asynchronously it could be modified to run forever with a simple
while(true) wrapping this code in the example:
// Wait for the message
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 with text: " + message.Text);
}
Its really up to you to define when your application exits. Once you've set your asynch consumer via:
consumer.Listener += new MessageListener(OnMessage);
it will receive messages until you close the consumer, session, or connection.
Regards
Tim.
--
Tim Bish
http://fusesource.com
http://timbish.blogspot.com/