Hello guys,

I've got a strange problem related to reading multiple messages from the
queue.
I have the following java logic to retrieve multiple messages defined by
variable "numberOfMessages":

Connection qConn=qFactory.createConnection();
qConn.start();   
Session qSession=qConn.createSession(false, QueueSession.AUTO_ACKNOWLEDGE); 
Destination queue=qSession.createQueue(qName);
MessageConsumer qReader=qSession.createConsumer(queue); 
TextMessage qMessage=null;
for(i=1;i<=numberOfMessages;++i){
    qMessage=(TextMessage)qReader.receive(DEFAULTWAITTIME);
    if(qMessage!=null){
                                // add qMessage to some storage
     }else{
        break;
    } 
}
qReader.close();
qSession.close();
qConn.close();

It works for a while; after that the logic is not able to retrieve any text
message from the queue.
The queue is not empty, but the qReader always returns null value, even
after I increased reading timeout.
If I restart ActiveMQ server, the above piece of code would work again.
Is there anybody who knows what happened to the code? Do I need to close the
MessageConsumer everytime I get a message?
Thanks.

Yelei

-- 
View this message in context: 
http://old.nabble.com/problem-related-to-reading-multiple-messages-from-the-queue-tp29045640p29045640.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to