You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Patrick Stekovic (JIRA)" <ji...@apache.org> on 2007/10/29 13:20:23 UTC

[jira] Created: (AMQ-1480) Problem with REST

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


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.


[jira] Reopened: (AMQ-1480) Problem with REST

Posted by "Patrick Stekovic (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Stekovic reopened AMQ-1480:
-----------------------------------


Please commit!

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


[jira] Resolved: (AMQ-1480) Problem with REST

Posted by "Patrick Stekovic (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Stekovic resolved AMQ-1480.
-----------------------------------

    Resolution: Fixed

http://www.nabble.com/REST-problem-tf4707322s2354.html

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


[jira] Updated: (AMQ-1480) Problem with REST

Posted by "Patrick Stekovic (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Stekovic updated AMQ-1480:
----------------------------------

    Attachment: patch.txt

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


[jira] Resolved: (AMQ-1480) Problem with REST

Posted by "Rob Davies (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1480?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Rob Davies resolved AMQ-1480.
-----------------------------

    Resolution: Fixed

This problem looks resolved now

> 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
>             Fix For: 5.3.0
>
>         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.


[jira] Commented: (AMQ-1480) Problem with REST

Posted by "Patrick Stekovic (JIRA)" <ji...@apache.org>.
    [ 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.