qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rajith Attapattu <rajit...@gmail.com>
Subject Re: Selective message acknowledgment in Java client (and C++ broker)?
Date Thu, 12 Apr 2012 17:21:10 GMT
On Thu, Apr 12, 2012 at 9:53 AM, Pavel Moravec <pmoravec@redhat.com> wrote:

> Hello,
> 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.:
>
> 1) Having CLIENT_ACKNOWLEDGE mode,
> 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 command:
> _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?
>

This method is used by the client ack mechanism, hence the need for
acknowling all messages up to that point.  As you pointed out there is no
way to selectively ack messages in JMS.

It's possible to add a method that would just do
_session.acknowledgeMessage(_deliveryTag, false);
However, I would not recommend using any of the inner classes and adding
hacks as it will prevent the user from easily upgrading to a newer version
if these classes change.

>
> Thanks in advance for your thoughs.
>
>
> Kind regards,
> Pavel
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message