You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by gminet <gm...@easynet.be> on 2007/05/20 15:28:33 UTC
Ajax/amq: Lost messages in MessageListenerServlet if more than
maxMessages waiting
Hi,
To test our ajax/amq application, we diminished the maximumMessages value in
MessageListenerServlet to some ridiculous value: 2 instead of 100.
We immediately began to lose every third message whenever there were more
that 2 messages waiting in the queue. I think we found the bug in
MessageListenerServlet:
In the following extract of doMessages() :
// Look for any available messages
message = consumer.receiveNoWait();
while (message != null && messages < maximumMessages) {
String id = (String) consumerIdMap.get(consumer);
writer.print("<response id='");
writer.print(id);
writer.print("'>");
writeMessageResponse(writer, message);
writer.println("</response>");
messages++;
message = consumer.receiveNoWait();
}
If we reach the messages > maximumMessages condition, the last one that has
been removed from the queue (message = consumer.receiveNoWait()) wont ever
be sent to the client;
If just added the following code as a quick fix after the while loop:
if (message != null) {
String id = (String) consumerIdMap.get(consumer);
writer.print("<response id='");
writer.print(id);
writer.print("'>");
writeMessageResponse(writer, message);
writer.println("</response>");
messages++;
}
Hope it helps
Regards
Gaetan
--
View this message in context: http://www.nabble.com/Ajax-amq%3A-Lost-messages-in-MessageListenerServlet-if-more-than-maxMessages-waiting-tf3785745s2354.html#a10705883
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
Re: Ajax/amq: Lost messages in MessageListenerServlet if more than maxMessages waiting
Posted by James Strachan <ja...@gmail.com>.
On 5/20/07, gminet <gm...@easynet.be> wrote:
>
> Hi,
>
> To test our ajax/amq application, we diminished the maximumMessages value in
> MessageListenerServlet to some ridiculous value: 2 instead of 100.
>
> We immediately began to lose every third message whenever there were more
> that 2 messages waiting in the queue. I think we found the bug in
> MessageListenerServlet:
>
> In the following extract of doMessages() :
>
> // Look for any available messages
> message = consumer.receiveNoWait();
> while (message != null && messages < maximumMessages) {
> String id = (String) consumerIdMap.get(consumer);
> writer.print("<response id='");
> writer.print(id);
> writer.print("'>");
> writeMessageResponse(writer, message);
> writer.println("</response>");
> messages++;
> message = consumer.receiveNoWait();
> }
>
> If we reach the messages > maximumMessages condition, the last one that has
> been removed from the queue (message = consumer.receiveNoWait()) wont ever
> be sent to the client;
>
> If just added the following code as a quick fix after the while loop:
>
> if (message != null) {
> String id = (String) consumerIdMap.get(consumer);
> writer.print("<response id='");
> writer.print(id);
> writer.print("'>");
> writeMessageResponse(writer, message);
> writer.println("</response>");
> messages++;
> }
>
> Hope it helps
>
> Regards
> Gaetan
Many thanks for the fix; patch applied on trunk!
I made a slight change to the code to avoid having to duplicate code;
I just split the boolean expression and moved the check for null
messages inside the while loop
--
James
-------
http://macstrac.blogspot.com/