activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Patrick Stekovic (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AMQ-1480) Problem with REST
Date Mon, 07 Jan 2008 16:47:43 GMT

    [ https://issues.apache.org/activemq/browse/AMQ-1480?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=40994#action_40994
] 

Patrick Stekovic commented on AMQ-1480:
---------------------------------------

Lets assume we want to consume one message from a queue that contains two messages, using
ActiveMQ's REST Interface with a HTTP GET request.
Looking at MessageServlet.java in the activemq-web module, the method doGet() calls the method
doMessages() :
{noformat}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
        doMessages(request, response, -1);
    }
{noformat}

As we are not using AJAX, the variable maxMessages gets the value 1:
{noformat}
protected void doMessages(HttpServletRequest request, HttpServletResponse response, int maxMessages)
throws ServletException,  IOException {
    ...
    boolean ajax = isRicoAjax(request);
    if (!ajax) {
        maxMessages = 1;
    }
    ...
}
{noformat}

In the synchronized()-block, we are consuming the first message in the queue:
{noformat}
synchronized(consumer){
    ...
    // Look for any available messages
    message = consumer.receiveNoWait();
    ...
}
{noformat}
Then, as message is not null and maxMessages has the value 1, we are entering the while-block:
{noformat}
               // send a response for each available message (up to max
               // messages)
               while ((maxMessages < 0 || messages < maxMessages) && message
!= null) {
                        // System.err.println("message["+messages+"]="+message);
                        if (ajax) {
                            writer.print("<response type='object' id='");
                            writer.print(request.getParameter("id"));
                            writer.println("'>");
                        } else {
                            // only ever 1 message for non ajax!
                            setResponseHeaders(response, message);
                        }

                        writeMessageResponse(writer, message);

                        if (ajax) {
                            writer.println("</response>");
                        }

                        // look for next message
                        message = consumer.receiveNoWait();
                        messages++;
                    } 
{noformat}
And here sitts the bug in my opinion. The method consumer.receiveNoWait() is called a second
time. That means, our second message gets deleted from the queue.

So I put the receiveNoWait() call in an if(ajax) block:
{noformat}                        
                       if (ajax){
                        	// look for next message
                        	message = consumer.receiveNoWait();
                        }
{noformat}

This works fine for me.

> Problem with REST
> -----------------
>
>                 Key: AMQ-1480
>                 URL: https://issues.apache.org/activemq/browse/AMQ-1480
>             Project: ActiveMQ
>          Issue Type: Bug
>    Affects Versions: 5.0.0
>         Environment: linux / jdk 1.5.0
>            Reporter: Patrick Stekovic
>         Attachments: patch.txt
>
>
> Every time I read one message (with REST/GET) from a queue with more than 1 message,
 two messages are deleted.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message