0 Replies Latest reply on Nov 8, 2011 5:41 AM by everson .

    Sometimes consume message, sometimes doesn't...

    everson . Newbie

      Hello!

       

      I have this code below and sometimes I can't consume a message, I get return null. But when I'll go to jboss admin-console and

      search on "list durable messages" using the message selector as I used inside the code it is found.

       

      Initially it happend when I call getMessage(..) inside a loop for(), so I thought it was a problem because of several calls. But happend again when just have

      one call. It doesn't happen everytime, just sometimes

       

      What could be wrong ??

       

       

      ObjectMessage om = jms.getMessage( "queue/MyQueue", "cpf='" + p.getCpf().trim()+ "'");

       

      public ObjectMessage getMessage( String lookup, String messageSelector) {

              Session session = null;

              Connection connection = null;

              ObjectMessage om = null;

              try {

                  ConnectionFactory factory = (QueueConnectionFactory) getInitialContext().lookup("/ConnectionFactory");//java:/ConnectionFactory

                  connection = factory.createConnection();

                  session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);

                  Destination destination = (Destination) getInitialContext().lookup(lookup);

                  MessageConsumer consumer = session.createConsumer(destination, messageSelector);

                  connection.start();

                  Message message = consumer.receive(5000);

                  om = (ObjectMessage) message;

              } catch (Exception e) {}

           return om;

      }