You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by savagre <sa...@gmail.com> on 2010/07/01 15:22:52 UTC

problem related to reading multiple messages from the queue

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.


Re: problem related to reading multiple messages from the queue

Posted by WuKo <sa...@gmail.com>.
Thanks Alexandre,
I'll try your solution.

Yelei

Hi Yelei,

You could try the following change to your jndi.properties file:
java.naming.provider.url = tcp://ws293.soadev.local:61616/localhost:1234

Where 1234 is a port you know to be open on the *client side*.


The local port number a client uses will most likely change from a
connection to the other. (ie: when a client opens a socket, the server port
is fixed to 61616 but the client port can be almost anything).

It is possible that, when your are lucky, all connections are established
using local ports that are not filtered by your firewall and that, when you
are unlucky, only the first connection "passes through". That could explain
the inconsistent behavior you experienced.

So try the change I proposed; it will tie the client to a fixed port number
(you can monitor your connections using jconsole to make sure your client
always uses the same port).


More info:
SSL & local address / local port:
http://activemq.apache.org/how-do-i-define-a-local-address-and-local-port-for-tcp-or-ssl.html
Monitoring using JMS: http://activemq.apache.org/jmx.html

Alexandre



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


Re: problem related to reading multiple messages from the queue

Posted by Alexandre Léveillé <le...@gmail.com>.
Hi Yelei,

You could try the following change to your jndi.properties file:
java.naming.provider.url = tcp://ws293.soadev.local:61616/localhost:1234

Where 1234 is a port you know to be open on the *client side*.


The local port number a client uses will most likely change from a
connection to the other. (ie: when a client opens a socket, the server port
is fixed to 61616 but the client port can be almost anything).

It is possible that, when your are lucky, all connections are established
using local ports that are not filtered by your firewall and that, when you
are unlucky, only the first connection "passes through". That could explain
the inconsistent behavior you experienced.

So try the change I proposed; it will tie the client to a fixed port number
(you can monitor your connections using jconsole to make sure your client
always uses the same port).


More info:
SSL & local address / local port:
http://activemq.apache.org/how-do-i-define-a-local-address-and-local-port-for-tcp-or-ssl.html
Monitoring using JMS: http://activemq.apache.org/jmx.html

Alexandre



On Fri, Jul 2, 2010 at 10:58, WuKo <sa...@gmail.com> wrote:

>
> Hi Alexandre,
>
> Thanks for your information.
> I think the configuration would be the cause of the problem.
>
> Here's the connector configuration from activemq.xml:
> <transportConnectors>
>             <transportConnector name="openwire" uri="tcp://0.0.0.0:61616
> "/>
> </transportConnectors>
> This part remains unchanged from default configuration.
> The activemq is hosted on server ws293.soadev.local
>
> Here's the configuration of jndi:
> java.naming.factory.initial =
> org.apache.activemq.jndi.ActiveMQInitialContextFactory
> java.naming.provider.url = tcp://ws293.soadev.local:61616
> ConnectionFactory = QueueConnectionFactory
> queue.OrderCreationQueue = OrderCreation
>
> In my case, should I change my jndi properties?
>
> Yelei
>
>
> Alexandre Léveillé wrote:
> >
> > Hi Yelei,
> >
> > If you think that your configuration may be the problem, please post your
> > [activemq_install_dir]/conf/activemq.xml and
> > [java_home]/lib/jndi.properties
> > files.
> >
> >
> > For instance, in activemq.xml you can set the broker to create the
> > transport
> > connectors of your choice:
> >
> > <transportConnectors>
> > <transportConnector name="ssl" uri="ssl://0.0.0.0:61617" />
> >  <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
> > </transportConnectors>
> >
> >
> > And then use the jndi.properties file so that the ActiveMQInitialContext
> > connects to your broker, using a specific local port.
> >
> > java.naming.provider.url = ssl://10.8.76.24:61617/localhost:60606
> >
> >
> > This is the kind of configuration I use, because I can only open specific
> > ports on both the client and the server. (In this example, the server is
> > listening on ssl://0.0.0.0:61617 and the client will connect through his
> > local port 60606)
> >
> > Alexandre
> >
> >
> > On Fri, Jul 2, 2010 at 09:26, WuKo <sa...@gmail.com> wrote:
> >
> >>
> >> 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 <sa...@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.
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/problem-related-to-reading-multiple-messages-from-the-queue-tp29045640p29057259.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>

Re: problem related to reading multiple messages from the queue

Posted by WuKo <sa...@gmail.com>.
Hi Alexandre,

Thanks for your information.
I think the configuration would be the cause of the problem.

Here's the connector configuration from activemq.xml:
<transportConnectors>
            <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>
This part remains unchanged from default configuration.
The activemq is hosted on server ws293.soadev.local

Here's the configuration of jndi:
java.naming.factory.initial =
org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://ws293.soadev.local:61616
ConnectionFactory = QueueConnectionFactory
queue.OrderCreationQueue = OrderCreation

In my case, should I change my jndi properties?

Yelei


Alexandre Léveillé wrote:
> 
> Hi Yelei,
> 
> If you think that your configuration may be the problem, please post your
> [activemq_install_dir]/conf/activemq.xml and
> [java_home]/lib/jndi.properties
> files.
> 
> 
> For instance, in activemq.xml you can set the broker to create the
> transport
> connectors of your choice:
> 
> <transportConnectors>
> <transportConnector name="ssl" uri="ssl://0.0.0.0:61617" />
>  <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
> </transportConnectors>
> 
> 
> And then use the jndi.properties file so that the ActiveMQInitialContext
> connects to your broker, using a specific local port.
> 
> java.naming.provider.url = ssl://10.8.76.24:61617/localhost:60606
> 
> 
> This is the kind of configuration I use, because I can only open specific
> ports on both the client and the server. (In this example, the server is
> listening on ssl://0.0.0.0:61617 and the client will connect through his
> local port 60606)
> 
> Alexandre
> 
> 
> On Fri, Jul 2, 2010 at 09:26, WuKo <sa...@gmail.com> wrote:
> 
>>
>> 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 <sa...@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.
>>
> 
> 

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


Re: problem related to reading multiple messages from the queue

Posted by Alexandre Léveillé <le...@gmail.com>.
Hi Yelei,

If you think that your configuration may be the problem, please post your
[activemq_install_dir]/conf/activemq.xml and [java_home]/lib/jndi.properties
files.


For instance, in activemq.xml you can set the broker to create the transport
connectors of your choice:

<transportConnectors>
<transportConnector name="ssl" uri="ssl://0.0.0.0:61617" />
 <transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>


And then use the jndi.properties file so that the ActiveMQInitialContext
connects to your broker, using a specific local port.

java.naming.provider.url = ssl://10.8.76.24:61617/localhost:60606


This is the kind of configuration I use, because I can only open specific
ports on both the client and the server. (In this example, the server is
listening on ssl://0.0.0.0:61617 and the client will connect through his
local port 60606)

Alexandre


On Fri, Jul 2, 2010 at 09:26, WuKo <sa...@gmail.com> wrote:

>
> 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 <sa...@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.
>

Re: problem related to reading multiple messages from the queue

Posted by WuKo <sa...@gmail.com>.
Hi Clark,

In this scenario, there's no specific requirements about when the messages
should be in the queue; because the consumer code is executed every several
minutes. The queue connection, session, consumer will be re-initialized.
As long as it's able to retrieve messages from the queue, it's considered to
be working. But the problem is that sometimes consumer fails to retrieve all
the messages; after that, no more messages can be retrieved from the queue,
even after connection is re-established.
I'll check the javadoc quote again to see if there's anything helpful.
Thank you for your help!

Yelei


cobrien wrote:
> 
> Yelei,
> This scenario requires the consumer to consume messages that were on the
> queue before the consumer started listening correct?  If this is the case
> please read the javadoc quote in  my previous response. 
> 
> Clark 
> 
> 
> www.ttmsolutions.com
> ActiveMQ reference guide at
> http://bit.ly/AMQRefGuide
> 
> 
> 
> 
> 
> 
> WuKo wrote:
>> 
>> 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 <sa...@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-tp29045640p29082740.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: problem related to reading multiple messages from the queue

Posted by cobrien <cl...@ttmsolutions.com>.
Yelei,
This scenario requires the consumer to consume messages that were on the
queue before the consumer started listening correct?  If this is the case
please read the javadoc quote in  my previous response. 

Clark 


www.ttmsolutions.com
ActiveMQ reference guide at
http://bit.ly/AMQRefGuide






WuKo wrote:
> 
> 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 <sa...@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-tp29045640p29065221.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: problem related to reading multiple messages from the queue

Posted by WuKo <sa...@gmail.com>.
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 <sa...@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.


Re: problem related to reading multiple messages from the queue

Posted by Alexandre Léveillé <le...@gmail.com>.
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 <sa...@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

Re: problem related to reading multiple messages from the queue

Posted by savagre <sa...@gmail.com>.
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.


Re: problem related to reading multiple messages from the queue

Posted by cobrien <cl...@ttmsolutions.com>.
Yelei
If DEFAULTWAITTIME expires then you will break out of your loop and not
receive any messages unless you restart.

Clark 

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-tp29045640p29048040.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.