Does JMS receiveNoWait() guarantee message delivery when messages are available?
<p>Hello I am writing some kind of simple testing scenario where I execute the following source code:</p>

<p><strong>Here is my send() method:</strong></p>

<pre><code>public void send() throws JMSException {

    Session session = null;
    MessageProducer producer = null;

    try {
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        Destination destination = session.createQueue("TEST.FOO");

        producer = session.createProducer(destination);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        byte[] uselessData = new byte[1024];

        BytesMessage message = session.createBytesMessage();
        message.writeBytes(uselessData);

        producer.send(message);

    } finally {
        producer.close();
        session.close();
    }
}
</code></pre>

<p><strong>Here is my receive() method:</strong></p>

<pre><code>public void receive() throws JMSException {

    Session session = null;
    MessageConsumer consumer = null;

    try {
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue("TEST.FOO");
        consumer = session.createConsumer(destination);

        Message hugeMessage = consumer.receiveNoWait();

        if (hugeMessage == null) {
            System.out.println("Message was not received");
            unsucsesfullCount++;
        } else {
            if (hugeMessage instanceof BytesMessage) {
                System.out.println("Message received");
            }
        }
    } finally {
        consumer.close();
        session.close();
    }

}
</code></pre>

<p><strong>I execute:</strong></p>

<pre><code>send();
receive();
</code></pre>

<p>The message value after <strong>receiveNoWait()</strong> is always <strong>null</strong>.</p>

<p>My question here is does the <strong>receiveNoWait()</strong> guarantee message delivery when there are messages in the broker? The <strong>send()</strong> is executed successfully so there is at least one message in the destination.</p>

<p>I've searched in the specification but there is not really clear definition if a message, which is available at the broker side should be explicitly received by <strong>receiveNoWait()</strong> at client side.</p>

<p>Also I want to ask, if <strong>receiveNoWait()</strong> does not have message available, should it trigger some refresh consumer process in the broker, so the next <strong>receiveNoWait()</strong> will receive the message?</p>

<p>The example code I provided run on ActiveMQ but my question is more conceptual than provider specific, because I have the same observation for other JMS providers.</p>