activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From WuKo <sava...@gmail.com>
Subject Re: problem related to reading multiple messages from the queue
Date Fri, 02 Jul 2010 13:26:35 GMT

Hello Alexandre,

Thanks for your reply.
You are right that that the consumer code will stop receiving messages after
it gets a timeout.

The scenario in my environment is:
1. we have a scheduler on one of our SOA platforms, which triggers the
consumer code every 5 minutes and gets a certain amount of messages from the
queue.
2. Everytime the consumer code is triggered, the connection will be started
again, and the consumer will be created again, as shown in the code.

The problem is:
1. We have 12 messages in the queue;
2. Everytime we read 5 messages from the queue.
3. The first time, we got 5 messages from the queue without any problem.
4. The second time, we got only 4 messages with the consumer code. 
5. 3 messages remain in the queue and are not able to get retrieved.
6. We kill the client connection, and try retrieving messages again. It
didn't work.
7. We restarted ActiveMQ, and use the same code to get messages. It started
working.

Sometimes we retrieve 12 messages from the queue by reading 5 messages 3
times; and then we add a few messages to queue, and do the retrieval again,
it still works with the consumer code.

Is there any configuration I need to do to make it always work? Currently
this problem occurs every day.
I think some port from the server side was blocked for some reason; maybe
it's due to my implementation, and I didn't have experience with ActiveMQ
before.

Thanks.

Yelei




Alexandre Léveillé wrote:
> 
> Hi Yelei,
> 
> As I see it, your loop will read a few messages. Then, the queue will be
> empty and your loop will go in the Else branch of your If. The break
> statement will then break your loop as Clark said, thus effectively you
> will
> stop receiving messages.
> 
> Hope that helps,
> Alexandre
> 
> 
> On Fri, Jul 2, 2010 at 06:58, savagre <savagre@gmail.com> wrote:
> 
>>
>> 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.
>>
>>
> 
> 
> -- 
> Visitez ma page du Cyclo-défi contre le cancer : www.alexandreleveille.ca
> 
> 

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


Mime
View raw message