views:

151

answers:

2

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;

      try
      {
         InitialContext jndi = new InitialContext();

            ConnectionFactory qFactory = (ConnectionFactory)jndi.
                lookup("myConnectionFactory");
              conn = qFactory.createConnection();
              conn.start();
         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...
         }
+1  A: 

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.

vdr
A: 

Does this code run in the appserver? If it does, I'd obtain the required objects via annotations, and for a message receiver I'd use a MDB. If this is a piece of standalone code, I had a hell of a time getting a JNDI based client working, I reverted to using the "raw" Java API.

fvu