Yaron Naveh Yaron Naveh - 1 year ago 99
Java Question

JMS client does not receive messages

I am using Glassfish JMS.

I am able to add messages to a queue.
I can see the messages using the QueueBrowser object.
However the MessageConsumer (nor the QueueReceiver) cannot receice any message and return null.
Message expiration is set to 0 and I remember to open the connection.

Any ideas?

Here is the code:

Session session = null;
Connection conn = null;

InitialContext jndi = new InitialContext();

ConnectionFactory qFactory = (ConnectionFactory)jndi.
conn = qFactory.createConnection();
Queue queue = (Queue)jndi.lookup("myQueueName");
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

QueueReceiver mc = ((QueueSession)session).createReceiver(queue);

Object m = mc.receive(2000);
//m is NULL!

QueueBrowser browser = session.createBrowser(queue);

for(Enumeration e = browser.getEnumeration(); e.hasMoreElements(); )
//there are many messages here...

vdr vdr
Answer Source

That would be good to have the client code.

Similar thing happened to me when not properly committing/closing the connection on the sender side. The message would be visible when using the admin console, however, not available yet to the MDB.

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download