NMS C# client Recieve not timing out

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NMS C# client Recieve not timing out

robottaway
I am guessing that the Recieve function on the ActiveMQ message consumer in the NMS api should return null when no messages are on a queue. I am not seeing this. I try to check for messages after receive, making sure that they are not null. What happens is that execution stops at the consumer.Receive() call, and does not move forward until a message comes into the queue.

What I am trying to do is the following: I have a windows service that will consume messages from a queue. When it starts up I want to try and read all messages on the queue. Once the initial messages are done being read I want to have the consumer stop, and another consumer with a MessageListener takes over. I register the MessageListener on another consumer so that any new messages that come into the queue will be read asynchronously.

I can make one or the other work, but not both. This is because the Receive function does not return when there are no messages on the queue I am reading from.
Reply | Threaded
Open this post in threaded view
|

Re: NMS C# client Recieve not timing out

chirino
Try using ReceiveNoWait or Receive with the time span.  Receive() is ment to
block until a message arrives.

On 10/23/06, robottaway <[hidden email]> wrote:

>
>
> I am guessing that the Recieve function on the ActiveMQ message consumer
> in
> the NMS api should return null when no messages are on a queue. I am not
> seeing this. I try to check for messages after receive, making sure that
> they are not null. What happens is that execution stops at the
> consumer.Receive() call, and does not move forward until a message comes
> into the queue.
>
> What I am trying to do is the following: I have a windows service that
> will
> consume messages from a queue. When it starts up I want to try and read
> all
> messages on the queue. Once the initial messages are done being read I
> want
> to have the consumer stop, and another consumer with a MessageListener
> takes
> over. I register the MessageListener on another consumer so that any new
> messages that come into the queue will be read asynchronously.
>
> I can make one or the other work, but not both. This is because the
> Receive
> function does not return when there are no messages on the queue I am
> reading from.
> --
> View this message in context:
> http://www.nabble.com/NMS-C--client-Recieve-not-timing-out-tf2497328.html#a6961449
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>


--
Regards,
Hiram

Blog: http://hiramchirino.com
Reply | Threaded
Open this post in threaded view
|

Re: NMS C# client Recieve not timing out

robottaway
Thanks Hiram! I tried both of those suggestions before sending out the previous email, and neither would work :( But after reading your email I gave it another try and surprise it is working :) I don't know if some threading issue may have been causing the problem. I am working with Windows services, and previously was coding the messaging setup in the service's setup method. I moved out the setup to a method that gets called at a set time after the service starts. This seems to work.
Reply | Threaded
Open this post in threaded view
|

Re: NMS C# client Recieve not timing out

Anulok
In reply to this post by robottaway
How about just putting in in a separate thread and that way you could let the thread that calls consumer.Receive() just hang until another message arrives while your main thread does some other work?

robottaway wrote
I am guessing that the Recieve function on the ActiveMQ message consumer in the NMS api should return null when no messages are on a queue. I am not seeing this. I try to check for messages after receive, making sure that they are not null. What happens is that execution stops at the consumer.Receive() call, and does not move forward until a message comes into the queue.

What I am trying to do is the following: I have a windows service that will consume messages from a queue. When it starts up I want to try and read all messages on the queue. Once the initial messages are done being read I want to have the consumer stop, and another consumer with a MessageListener takes over. I register the MessageListener on another consumer so that any new messages that come into the queue will be read asynchronously.

I can make one or the other work, but not both. This is because the Receive function does not return when there are no messages on the queue I am reading from.