4 Replies Latest reply on Mar 23, 2007 3:30 PM by Jacek Kowalski

    Queue - I can send but cannot receive

    Jacek Kowalski Newbie

      Hello

      JBoss: 4.0.5 GA

      I'm still facing some problems working with JMS.
      The last problem is that i cannot receive message from queue. I can send it, but cannot receive it later. All from mothod inside simle stateless session bean. This method works in a transaction (Container, Required).

      First getting stuff

      InitialContext ictx = new InitialContext();
       ConnectionFactory cf = (ConnectionFactory) ictx.lookup("java:JmsXA");
       Connection con = cf.createConnection();
       Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
      
       Queue queue = (Queue ) ictx.lookup("queue/testQueue");
      
       logger.info(queue.getQueueName());


      Now we can perform some operations on queue:
      First we can send message:

      MessageProducer sender = session.createProducer(queue);
      
       Order order = new Order();
       order.setOrderId("orderId");
      
       Message message = session.createObjectMessage(order);
      
       sender.send(message);
       logger.info("Message has been sent");


      Sending messages works fine.
      Now i would like to receive one message:

      MessageConsumer consumer = session.createConsumer(queue);
       Message m = consumer.receiveNoWait();
      
       if (m == null){
       logger.error("m is null");
       }else{
       logger.info("got message, yupi");
       }


      But I cannot get message from queue "testQueue". Everytime single time i get null. Queue depth is huge now after so many tries :(

      I deployed MDB, and that MDB was able to consume messages from this queue. I have no idea what i'm doing wrong. Any sugestions?

      Thank you for all your replies in advance.

      vitor_b