activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brad Willard (JIRA)" <j...@apache.org>
Subject [jira] Created: (AMQ-2577) Acknowleging a single message actually acknowleges all messages consumed.
Date Thu, 21 Jan 2010 19:13:43 GMT
Acknowleging a single message actually acknowleges all messages consumed.
-------------------------------------------------------------------------

                 Key: AMQ-2577
                 URL: https://issues.apache.org/activemq/browse/AMQ-2577
             Project: ActiveMQ
          Issue Type: Bug
          Components: JMS client
    Affects Versions: 5.3.0
         Environment: Mac OSX 10.6, CentOS 5 Linux
            Reporter: Brad Willard


If I publish a bunch of messages, and then consume them with a session Session.CLIENT_ACKNOWLEDGE,
when I acknowlege the first messages, all messages actually get acknowledged.  I'm including
some source code that shows the problem.

This problem can be seen regardless of the Session be transacted or not.

Thanks,
Brad


package bugs;

import javax.jms.*;
import java.util.LinkedList;
import java.net.*;
import org.apache.activemq.*;

/**
 *
 * @author bwillard
 */
public class MessageAcknowledgementBug {

    public static void main(String[] args) {

        try {

            ConnectionFactory factory = new ActiveMQConnectionFactory(URI.create("tcp://localhost:61616"));

            Connection jmsConn = factory.createConnection();
            jmsConn.start();

            Session session = jmsConn.createSession(false, Session.CLIENT_ACKNOWLEDGE);

            Queue queue = session.createQueue("Ack.Bug.Test");

            MessageProducer publisher = session.createProducer(queue);
            TextMessage msg;

            /*
             * Put 50 Messages on Queue
             */
            for (int a = 0; a < 50; a++) {
                msg = session.createTextMessage("" + a);
                publisher.send(msg);
            }



            MessageConsumer reader = session.createConsumer(queue);

            LinkedList<TextMessage> messages = new LinkedList<TextMessage>();


            /*
             * Receive all 50 messages and store in list
             */

            while ((msg = (TextMessage) reader.receiveNoWait()) != null) {
                messages.add(msg);
            }



            /*
             * acknowledge one message, which acknowledges them all as received
             * instead of just the one message
             */

            messages.getFirst().acknowledge();



            reader.close();
            publisher.close();

            jmsConn.stop();
            jmsConn.close();



        } catch (Exception exc) {
            exc.printStackTrace();
        }


    }
}

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