From users-return-6126-apmail-qpid-users-archive=qpid.apache.org@qpid.apache.org Thu Apr 12 17:21:38 2012 Return-Path: X-Original-To: apmail-qpid-users-archive@www.apache.org Delivered-To: apmail-qpid-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8F6519D44 for ; Thu, 12 Apr 2012 17:21:38 +0000 (UTC) Received: (qmail 32806 invoked by uid 500); 12 Apr 2012 17:21:38 -0000 Delivered-To: apmail-qpid-users-archive@qpid.apache.org Received: (qmail 32760 invoked by uid 500); 12 Apr 2012 17:21:38 -0000 Mailing-List: contact users-help@qpid.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@qpid.apache.org Delivered-To: mailing list users@qpid.apache.org Received: (qmail 32751 invoked by uid 99); 12 Apr 2012 17:21:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Apr 2012 17:21:38 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rajith77@gmail.com designates 209.85.212.174 as permitted sender) Received: from [209.85.212.174] (HELO mail-wi0-f174.google.com) (209.85.212.174) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Apr 2012 17:21:31 +0000 Received: by wibhr17 with SMTP id hr17so4888461wib.15 for ; Thu, 12 Apr 2012 10:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ssxMO8npQ1yftDR43U9C12BR4H5TNfzlzfO9Y+HNIqo=; b=EanzpyVk6qXFVGKhefl/VhIAa2oR2Mdhi8nMwBcK9aUj5nNhSRFxMY498hfeUaZGEO GurEtAnA2lLMdmZoCMp2XOkV5sq0Y5+QhiHtfR9khKsDUgOQK7XPqRujtW8mCaS6ePhd l0iGM1x7tuUKvoBbKM235TL1lgpmc2nyxJ5PkQZrQkD877k7lzkZcQjiOHlCpVAg4dVJ tL4PO16jXaEsbJr5aUnrrjaKwyqpXGf3F7Og4SYDGPsXF2Z0ptkyLqC9HY2iUwUd+l6E 9xXMjYAHdEzUPCKgRJOMAtzxFbaxW5FW4YAS4SQyS3TMZxHtK1wgxX5+tRD7x24dq+RM jVCQ== MIME-Version: 1.0 Received: by 10.216.134.27 with SMTP id r27mr2004473wei.107.1334251270178; Thu, 12 Apr 2012 10:21:10 -0700 (PDT) Received: by 10.216.38.1 with HTTP; Thu, 12 Apr 2012 10:21:10 -0700 (PDT) In-Reply-To: <4f88a586-0276-4fdc-a191-416b58d00c81@zmail02.collab.prod.int.phx2.redhat.com> References: <532c36b6-a6c4-4905-b3fd-d39ec31839a4@zmail02.collab.prod.int.phx2.redhat.com> <4f88a586-0276-4fdc-a191-416b58d00c81@zmail02.collab.prod.int.phx2.redhat.com> Date: Thu, 12 Apr 2012 13:21:10 -0400 Message-ID: Subject: Re: Selective message acknowledgment in Java client (and C++ broker)? From: Rajith Attapattu To: users@qpid.apache.org Content-Type: multipart/alternative; boundary=0016e6d6467300091a04bd7e9506 X-Virus-Checked: Checked by ClamAV on apache.org --0016e6d6467300091a04bd7e9506 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Apr 12, 2012 at 9:53 AM, Pavel Moravec 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 > > --0016e6d6467300091a04bd7e9506--