qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pavel Moravec <pmora...@redhat.com>
Subject Selective message acknowledgment in Java client (and C++ broker)?
Date Thu, 12 Apr 2012 13:53:52 GMT
having Java client and C++ broker, I want to implement selective consumption of messages from
a queue (something like JMS message selectors in Java broker). I.e.:

2) In a loop through all messages of the queue:
   a) receive a message
   b) decide if to consume or not
   c) if so, acknowledge it, if not so, ignore it
3) Close the session to retrieve the unacknowledged messages back to the queue.

However, I see no way of doing so.

Method Message.acknowledge(); is not suitable as it acknowledges also all previous messages,
following JMS specification.

Using method AbstractJMSMessage.acknowledgeThis(), I got the same results. Though the method
name would suggest, it shall acknowledge just this message, no else. But checking source code:

    public void acknowledgeThis() throws JMSException
        // the JMS 1.1 spec says in section 3.6 that calls to acknowledge are ignored when
client acknowledge
        // is not specified. In our case, we only set the session field where client acknowledge
mode is specified.
        if (_session != null && _session.getAcknowledgeMode() == Session.CLIENT_ACKNOWLEDGE)
            if (_session.getAMQConnection().isClosed())
                throw new javax.jms.IllegalStateException("Connection is already closed");

            // we set multiple to true here since acknowledgment implies acknowledge of all
previous messages
            // received on the session
            _session.acknowledgeMessage(_deliveryTag, true);

See the latest comment - it acknowledges all previous messages on purpose. Having the last
_session.acknowledgeMessage(_deliveryTag, false);

only this message will be acknowledged, no else.

Is there some reason for this behavior? If so, how can I achieve a real single message acknowledgment?

Thanks in advance for your thoughs.

Kind regards,

To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org

View raw message