You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by mjustin <mi...@gmx.net> on 2009/04/16 11:37:26 UTC

Stomp ack:auto clears all remaining messages in the queue

Hello,

I compared the behaviour of the JMS client (using the ProducerTool and
ConsumerTool) and the behaviour of the Stomp client in Java.

In both tests I start with 20 messages which I send to the queue
TOOL.DEFAULT:


call java -cp .;activemq-all-5.3-SNAPSHOT.jar ProducerTool --MessageCount=20

Then I verify that the queue contains 20 messages:

start http://localhost:8161/admin/browse.jsp?JMSDestination=TOOL.DEFAULT

First I run the test of the JMS Client, consuming 10 messages using
AUTO_ACKNOWLEDGE: 

java -cp .;activemq-all-5.3-SNAPSHOT.jar ConsumerTool
--AckMode=AUTO_ACKNOWLEDGE --MaxiumMessages=10 --verbose

Then I verify that there are 10 messages remaining in the queue, with the
'Redelivered' fag set.

Finally I read the remaining queue entries using the same command as before.

Now I start again, sending 20 messages to the queue.

With the Stomp Java client, I read ten messages:

    public void testSubscribeWithAutoAck() throws Exception {

        String frame = "CONNECT\n" + "login: system\n" + "passcode:
manager\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        frame = stompConnection.receiveFrame();
        System.out.println(frame);

        frame = "SUBSCRIBE\n" + "destination:/queue/TOOL.DEFAULT" + "\n" +
"ack:auto\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        for (int i=0; i < 10; i++) {
          frame = stompConnection.receiveFrame();
            System.out.println(frame);
        }

        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        System.out.println("Disconnect frame sent");
    }


Now I check the queue in the admin console: there should be ten remaining
messages in the queue, but the queue is empty.

All 20 messages have been sent to the client over the Stomp adapter (as I
can see in the broker log), but the broker does not realize that the client
has received only 10.

So the difference between the JMS and the Stomp interface is that the JMS
interface allows to fetch some messages using automatic acknowledge, while
the Stomp client (using ack:auto) would require to read all remaining
messages - if it stops receiving, all remaining messages are lost.

I am not sure if this is 'as designed', however it seems to make automatic
acknowledgement in the Stomp interface very fragile.

Best Regards
Michael Justin
-- 
View this message in context: http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23074533.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Stomp ack:auto clears all remaining messages in the queue

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi Michael,

thanks for these updates. Please provide details on any issues you
experience (and raise appropriate Jira issues).

Cheers
--
Dejan Bosanac

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net


On Fri, Apr 17, 2009 at 6:46 PM, mjustin <mi...@gmx.net> wrote:

>
> Update #2:
>
> Looks like it is only a problem in the Stomp Java client in ActiveMQ - I
> will try to fix the source of my tests to see if it is a protocol error
> (missing unsubscribe) or a problem in the underlying TCP transport layer.
>
> After some tweaking, my Delphi library shows and better results now -
> depending on the steps at the end of the communication (unsubscribing,
> disconnecting).
>
> Many thanks for your feedback,
> and for bringing Hudson online :)
>
> Michael
>
>
> mjustin wrote:
> >
> > Update:
> >
> > the test steps and results are:
> >
> > 1. send 20 messages to the broker, the admin console displays 20
> messages,
> > numbered from 1 to 20
> >
> > 2. consume 10 messages using Stomp client (5.3-Snapshot version) with
> > "ack:auto", now the admin console displays only messages numbered from 13
> > to 20 - it looks like message 11 and 12 are lost
> >
> > 3. try to consume 10 messages again: the Stomp client only receives 8
> > messages
> >
> > I will try it with the current snapshot
> >
> > Best Regards,
> > Michael Justin
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23101402.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>

Re: Stomp ack:auto clears all remaining messages in the queue

Posted by mjustin <mi...@gmx.net>.
Update #2:

Looks like it is only a problem in the Stomp Java client in ActiveMQ - I
will try to fix the source of my tests to see if it is a protocol error
(missing unsubscribe) or a problem in the underlying TCP transport layer.

After some tweaking, my Delphi library shows and better results now -
depending on the steps at the end of the communication (unsubscribing,
disconnecting).

Many thanks for your feedback,
and for bringing Hudson online :)

Michael


mjustin wrote:
> 
> Update:
> 
> the test steps and results are:
> 
> 1. send 20 messages to the broker, the admin console displays 20 messages,
> numbered from 1 to 20
> 
> 2. consume 10 messages using Stomp client (5.3-Snapshot version) with
> "ack:auto", now the admin console displays only messages numbered from 13
> to 20 - it looks like message 11 and 12 are lost
> 
> 3. try to consume 10 messages again: the Stomp client only receives 8
> messages
> 
> I will try it with the current snapshot
> 
> Best Regards,
> Michael Justin
> 
> 

-- 
View this message in context: http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23101402.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Stomp ack:auto clears all remaining messages in the queue

Posted by mjustin <mi...@gmx.net>.
Update:

the test steps and results are:

1. send 20 messages to the broker, the admin console displays 20 messages,
numbered from 1 to 20

2. consume 10 messages using Stomp client (5.3-Snapshot version) with
"ack:auto", now the admin console displays only messages numbered from 13 to
20 - it looks like message 11 and 12 are lost

3. try to consume 10 messages again: the Stomp client only receives 8
messages

I will try it with the current snapshot

Best Regards,
Michael Justin

-- 
View this message in context: http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23100944.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Stomp ack:auto clears all remaining messages in the queue

Posted by mjustin <mi...@gmx.net>.
Hi Dejan,

thanks for the reply. I have found a classpath problem, which caused a wrong
version of StompConnection to be used (5.2 or an old 5.3 version).

Now I see that the behaviour is like this:

- first receive of 10 messages using Stomp: works fine
- Queue displays remaining 8 messages (of 20), should be 10
- reading of remaining 8 messages works fine, there are no other messages in
the Queue

So it looks like 2 messages are lost after the Stomp client has received the
initial 10 messages.

Here is the code, with a small change to display the current message index
instead of the full frame:

package javastompconsumer;

import java.io.IOException;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.activemq.transport.stomp.Stomp;
import org.apache.activemq.transport.stomp.StompConnection;

/**
 *
 * @author Michael
 */
public class Main {

    private StompConnection stompConnection = new StompConnection();
    protected String bindAddress = "stomp://localhost:61613";

    private void stompConnect() throws IOException, URISyntaxException,
UnknownHostException {
        URI connectUri = new URI(bindAddress);
        stompConnection.open(createSocket(connectUri));
    }

    protected Socket createSocket(URI connectUri) throws IOException {
        return new Socket("127.0.0.1", connectUri.getPort());
    }

    private void stompDisconnect() throws IOException {
        if (stompConnection != null) {
            stompConnection.close();
            stompConnection = null;
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

        Main main = new Main();
        try {
            main.run();
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (URISyntaxException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null,
ex);
        }



    }

    private void run() throws IOException, URISyntaxException, Exception {
        stompConnect();

        String frame = "CONNECT\n" + "login: system\n" + "passcode:
manager\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        frame = stompConnection.receiveFrame();
        System.out.println(frame);

        frame = "SUBSCRIBE\n" + "destination:/queue/TOOL.DEFAULT" + "\n" +
"ack:auto\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        for (int i = 0; i < 10; i++) {
            frame = stompConnection.receiveFrame();
            // System.out.println(frame);
            System.out.println(i + 1);
        }

        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);
        System.out.println("Disconnect frame sent");

        stompDisconnect();
    }
}

-- 
View this message in context: http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23078082.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Re: Stomp ack:auto clears all remaining messages in the queue

Posted by Dejan Bosanac <de...@nighttale.net>.
Hi Michael,

can you consume other ten messages afterwards? can you try to disconnect
your current consumer, subscribe again and try to consume remaining
messages?



Cheers
--
Dejan Bosanac

Open Source Integration - http://fusesource.com/
ActiveMQ in Action - http://www.manning.com/snyder/
Blog - http://www.nighttale.net


On Thu, Apr 16, 2009 at 11:37 AM, mjustin <mi...@gmx.net> wrote:

>
> Hello,
>
> I compared the behaviour of the JMS client (using the ProducerTool and
> ConsumerTool) and the behaviour of the Stomp client in Java.
>
> In both tests I start with 20 messages which I send to the queue
> TOOL.DEFAULT:
>
>
> call java -cp .;activemq-all-5.3-SNAPSHOT.jar ProducerTool
> --MessageCount=20
>
> Then I verify that the queue contains 20 messages:
>
> start http://localhost:8161/admin/browse.jsp?JMSDestination=TOOL.DEFAULT
>
> First I run the test of the JMS Client, consuming 10 messages using
> AUTO_ACKNOWLEDGE:
>
> java -cp .;activemq-all-5.3-SNAPSHOT.jar ConsumerTool
> --AckMode=AUTO_ACKNOWLEDGE --MaxiumMessages=10 --verbose
>
> Then I verify that there are 10 messages remaining in the queue, with the
> 'Redelivered' fag set.
>
> Finally I read the remaining queue entries using the same command as
> before.
>
> Now I start again, sending 20 messages to the queue.
>
> With the Stomp Java client, I read ten messages:
>
>    public void testSubscribeWithAutoAck() throws Exception {
>
>        String frame = "CONNECT\n" + "login: system\n" + "passcode:
> manager\n\n" + Stomp.NULL;
>        stompConnection.sendFrame(frame);
>
>        frame = stompConnection.receiveFrame();
>        System.out.println(frame);
>
>        frame = "SUBSCRIBE\n" + "destination:/queue/TOOL.DEFAULT" + "\n" +
> "ack:auto\n\n" + Stomp.NULL;
>        stompConnection.sendFrame(frame);
>
>        for (int i=0; i < 10; i++) {
>          frame = stompConnection.receiveFrame();
>            System.out.println(frame);
>        }
>
>        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
>        stompConnection.sendFrame(frame);
>
>        System.out.println("Disconnect frame sent");
>    }
>
>
> Now I check the queue in the admin console: there should be ten remaining
> messages in the queue, but the queue is empty.
>
> All 20 messages have been sent to the client over the Stomp adapter (as I
> can see in the broker log), but the broker does not realize that the client
> has received only 10.
>
> So the difference between the JMS and the Stomp interface is that the JMS
> interface allows to fetch some messages using automatic acknowledge, while
> the Stomp client (using ack:auto) would require to read all remaining
> messages - if it stops receiving, all remaining messages are lost.
>
> I am not sure if this is 'as designed', however it seems to make automatic
> acknowledgement in the Stomp interface very fragile.
>
> Best Regards
> Michael Justin
> --
> View this message in context:
> http://www.nabble.com/Stomp-ack%3Aauto-clears-all-remaining-messages-in-the-queue-tp23074533p23074533.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>