You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by "Klaus.Unger" <kl...@iq-consultancy.net> on 2011/09/14 18:07:55 UTC

Troubles receiving a Message with a Selector

Hello everybody,

I did search the forum for some similar questions/problems, but didn't find
matching entries.

I normally work with the Spring JmsTemplate, but did also try to reproduce
the problematic behaviour in a native ActiveMQ Java implementation.

// given factory is a ActiveMQConnectionFactory
        sendConnection = factory.createConnection();
        sendConnection.start();

        receiveConnection = factory.createConnection();
        receiveConnection.start();
 
        RecognitionSession recognitionSession = ... // my payload in the jms
message
        String selector = String.format("JMSCorrelationID='%s'",
recognitionSession.getClientSessionId());
 
        Session sendSession = sendConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = sendSession.createProducer(queue);
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        Message message =
sendSession.createObjectMessage(recognitionSession);
       
message.setJMSCorrelationID(recognitionSession.getClientSessionId());
        message.setJMSTimestamp(System.currentTimeMillis());
        producer.send(message);
 
        Session receiveSession = receiveConnection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = receiveSession.createConsumer(queue,
selector);
        ObjectMessage receivedMessage = (ObjectMessage)
consumer.receive(25);
        RecognitionSession receivedRecognitionSession = null;

        if (receivedMessage != null) {
            receivedRecognitionSession = (RecognitionSession)
receivedMessage.getObject();
        }

        QueueBrowser browser = receiveSession.createBrowser(queue,
selector);
        // further checks if the recognitionSession is not in the delivered
Enumeration anymore

I did call this code in a kind of stress test 5000 times!

4964 times the message was received,
26 times the message receive(25) delivered null

any ideas, any hints welcome


--
View this message in context: http://activemq.2283324.n4.nabble.com/Troubles-receiving-a-Message-with-a-Selector-tp3813397p3813397.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: Troubles receiving a Message with a Selector

Posted by Torsten Mielke <to...@fusesource.com>.
> 
> I did call this code in a kind of stress test 5000 times!
> 
> 4964 times the message was received,
> 26 times the message receive(25) delivered null

Was the message always available on the brokers queue when you called consumer.receive(25)?
Have you tried extending the timeout on receive() or putting a short sleep between sending and consuming the msg?
Is it really related to using msg selectors?

I presume your broker is a separate JVM process. Even though ActiveMQ will only send back a producer ack once it has persisted the msg (and hence has pretty much put it on the queue) I still wonder if this is a timing issue. A short sleep between send and receive should confirm or correct this. 


Torsten Mielke
torsten@fusesource.com
tmielke@blogspot.com