activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Posta <christian.po...@gmail.com>
Subject Re: standard jms code can not receive message from queue
Date Thu, 26 Sep 2013 22:18:04 GMT
This is not a bug.

>From the JMS API doc:
http://docs.oracle.com/javaee/1.4/api/javax/jms/MessageConsumer.html#receiveNoWait()

"Receives the next message if one is immediately available."
Could be the broker hasn't dispatched the message yet, or it's in flight,
etc, etc. so it's not "immediately available"

If you code for receiveNoWait() you have to understand its ramifications
and plan for it accordingly.




On Thu, Sep 26, 2013 at 1:08 PM, zbc <zhebincong@163.com> wrote:

> please look at following code:
>
>             InitialContext ctx = null;
>             QueueConnection con = null;
>             QueueSession queueSession = null;
>             QueueReceiver receiver = null;
>             try {
>               Hashtable env = new Hashtable();
>               env = new Hashtable();
>               env.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
>               env.put(Context.PROVIDER_URL, "tcp://localhost:61616");
>               ctx = new InitialContext(env);
>               QueueConnectionFactory fac =
> (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
>               con = fac.createQueueConnection();
>               queueSession = con.createQueueSession(false,
> Session.AUTO_ACKNOWLEDGE);
>               con.start();
>               receiver =
>
> queueSession.createReceiver((Queue)ctx.lookup("dynamicQueues/FromReqRespClient"));
>               Message result = receiver.receiveNoWait();
>               System.out.println(result);
>             } catch (Exception e) {
>                 e.printStackTrace();
>             } finally {
>                 close();
>             }
>
>
> this is standard jms code, but it can NOT receive message from queue, if
> you
> add a line "Thread.sleep(500)" before "Message result =
> receiver.receiveNoWait(); ", it WORKS. this code work well to openJMS, is
> it
> a bug? you can try yourself, thanks.
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/standard-jms-code-can-not-receive-message-from-queue-tp4671868.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>



-- 
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message