activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <>
Subject Re: Setting up a C# ActiveMQ listener
Date Wed, 30 Sep 2009 17:36:50 GMT
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
> 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!");
        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

	consumer.Listener += new MessageListener(OnMessage);

it will receive messages until you close the consumer, session, or connection.


Tim Bish

View raw message