[jboss-user] [JBoss Messaging] - Sometimes consume message, sometimes doesn't...

everson . do-not-reply at jboss.com
Tue Nov 8 05:41:21 EST 2011


everson . [http://community.jboss.org/people/everjava] created the discussion

"Sometimes consume message, sometimes doesn't..."

To view the discussion, visit: http://community.jboss.org/message/635513#635513

--------------------------------------------------------------
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;
}
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/635513#635513]

Start a new discussion in JBoss Messaging at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111108/3de9896f/attachment.html 


More information about the jboss-user mailing list