Hello Clark, Thanks a lot for your reply. I understand that the 'receive' method only retrieves the message within the interval defined by the wait time. But the messages in the queue is really small, like 5 or 6 lines of text; and I already increased the wait time to 10 seconds (10000). When the code works, it's able to read exactly the same message within miliseconds. The only way I found to get it resolved is to restart the ActiveMQ server; and then the same code is able to pick up messages again. Do you know what could be the problem here?
Yelei cobrien wrote: > > Yelei > If DEFAULTWAITTIME expires then you will break out of your loop and not > receive any messages unless you restart. > > The link below has an example of implementing a Consumer. > http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html > > > Clark > PS > Note that the JMS API JavaDoc for the API 'receive' method says > "Receives the next message that arrives within the specified timeout > interval." > > www.ttmsolutions.com > ActiveMQ reference guide at > http://bit.ly/AMQRefGuide > > > > savagre wrote: >> >> 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-tp29045640p29055019.html Sent from the ActiveMQ - User mailing list archive at Nabble.com.