You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Brad Willard (JIRA)" <ji...@apache.org> on 2010/01/21 20:13:43 UTC

[jira] Created: (AMQ-2577) Acknowleging a single message actually acknowleges all messages consumed.

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.


[jira] Commented: (AMQ-2577) Acknowleging a single message actually acknowleges all messages consumed.

Posted by "Timothy Bish (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQ-2577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=57044#action_57044 ] 

Timothy Bish commented on AMQ-2577:
-----------------------------------

This is actually exactly how CLIENT_ACKNOWLEDGE works.  

>From the JMS Specification:

With this acknowledgment mode, the client acknowledges a consumed message by calling the message's acknowledge method. Acknowledging a consumed message acknowledges all messages that the session has consumed. 

ActiveMQ has a special acknowledge mode called INDIVIDUAL_ACKNOWLEDGE that can be used if you really want to ack only a single message at a time.



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


[jira] Commented: (AMQ-2577) Acknowleging a single message actually acknowleges all messages consumed.

Posted by "Brad Willard (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQ-2577?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=57045#action_57045 ] 

Brad Willard commented on AMQ-2577:
-----------------------------------

Wow is that a misleading flaw in the JMS Spec, I guess I'll go write them about that.  Thanks for the info on INDIVIDUAL_ACKNOWLEDGE.  I just started using that and it works like a charm.

Thanks,
Brad

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


[jira] Closed: (AMQ-2577) Acknowleging a single message actually acknowleges all messages consumed.

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

Brad Willard closed AMQ-2577.
-----------------------------

       Resolution: Working as Designed
    Fix Version/s: 5.3.0

This behavior is defined in the JMS Specification.  I think this is really a flaw in the design of the specification.  ActiveMQ supports the spec properly, it's the spec that's misleading.

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