It seems to be provider specific. Many JMS providers will treat
"Receives the next message if one is immediately available" literally
- i.e. not to wait for a request/response with the broker to check if
there is a message available for processing. This is what ActiveMQ
does and a number of other JMS providers do the same - but its
provider specific.

At the very least you should wait some period of time (say 1 second)
after creating your consumer before issuing a receiveNoWait() if you
want your code to work with most JMS providers - or use receive(1000)
on the first call - then use receiveNoWait() afterwards etc.

2008/8/26 Jecsiac <[EMAIL PROTECTED]>:
>
>>receiveNoWait() is not meant to wait for a message to arrive. In
>>ActiveMQ creating a receiver does not block until messages are
>>received.
>
>>i.e. its not really JMS compliant to use receiveNoWait() and not
>>expect nulls to come back if you've not really left much time for the
>>JMS provider to actually find the messages and return them over the
>
> JMS 1.1 Specification has no words on receiveNoWait() (at least in it's PDF
> document). And in JMS 1.1 API document, it just said:
>
> receiveNoWait
> public Message receiveNoWait()
>                      throws JMSException
> Receives the next message if one is immediately available.
> Returns:
> the next message produced for this message consumer, or null if one is not
> available
> Throws:
> JMSException - if the JMS provider fails to receive the next message due to
> some internal error.
>
> Maybe it is some amphibolous. So I think my expectation could also be
> proper: There're 2000 messages in the queue, and the message I want to find
> is just in them, so why receiveNoWait() gives me a null? Of course, the
> provider needs time to find out the message. But in contrast with receive():
>
> receive
> public Message receive()
>                throws JMSException
> Receives the next message produced for this message consumer.
> This call blocks indefinitely until a message is produced or until this
> message consumer is closed.
>
> If this receive is done within a transaction, the consumer retains the
> message until the transaction commits.
>
> Returns:
> the next message produced for this message consumer, or null if this message
> consumer is concurrently closed
> Throws:
> JMSException - if the JMS provider fails to receive the next message due to
> some internal error.
>
> It seems NoWait could means no 'blocks indefinitely until a message is
> produced' —— but should it include the time the provider needs to find out
> the message? No more words. So maybe it is some amphibolous.
>
> --
> View this message in context: 
> http://www.nabble.com/Problem-with-Selector-tp19157015p19161717.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Reply via email to