Reading your query again, it seems you want selectors to work not really to do selective message acking. So I wondering why you can't use a jms selector ? The JMS client supports message selectors. I'm wondering why you need to use a workaround here ?
(Note for C++ broker we do client side selectors, which does exactly what you have described). Regards, Rajith On Thu, Apr 12, 2012 at 9:53 AM, Pavel Moravec <[email protected]> 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? > > Thanks in advance for your thoughs. > > > Kind regards, > Pavel > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
