activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mjustin <michael.jus...@gmx.net>
Subject Re: Stomp ack:auto clears all remaining messages in the queue
Date Thu, 16 Apr 2009 13:33:39 GMT

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.


Mime
View raw message