Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-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 116757957 for ; Thu, 1 Dec 2011 09:11:32 +0000 (UTC) Received: (qmail 27672 invoked by uid 500); 1 Dec 2011 09:11:31 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 27632 invoked by uid 500); 1 Dec 2011 09:11:30 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 27620 invoked by uid 99); 1 Dec 2011 09:11:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2011 09:11:28 +0000 X-ASF-Spam-Status: No, hits=1.6 required=5.0 tests=RCVD_IN_BRBL_LASTEXT,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [87.117.246.105] (HELO ganesha.artcore.com) (87.117.246.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 01 Dec 2011 09:11:23 +0000 Received: from mail-lpp01m010-f45.google.com ([209.85.215.45]:46841) by ganesha.artcore.com with esmtpsa (TLSv1:RC4-SHA:128) (Exim 4.69) (envelope-from ) id 1RW2fV-00035m-9D for users@camel.apache.org; Thu, 01 Dec 2011 09:11:01 +0000 Received: by laho5 with SMTP id o5so740453lah.32 for ; Thu, 01 Dec 2011 01:10:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.109.199 with SMTP id hu7mr3976181lab.16.1322730658530; Thu, 01 Dec 2011 01:10:58 -0800 (PST) Received: by 10.152.28.204 with HTTP; Thu, 1 Dec 2011 01:10:58 -0800 (PST) In-Reply-To: References: Date: Wed, 30 Nov 2011 21:10:58 -1200 Message-ID: Subject: Re: Transactions with PollingConsumerTemplate/producerTemplate From: Tom Howe To: users@camel.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ganesha.artcore.com X-AntiAbuse: Original Domain - camel.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - artcore.com Hi Claus, Thanks for your response - I've never done this before, would you be able to point me to some example code? Thanks, Tom On Wed, Nov 30, 2011 at 7:53 AM, Claus Ibsen wrote: > On Wed, Nov 30, 2011 at 5:06 PM, Tom Howe wrote: >> Hi, >> >> If I want to consumer from a queue using PollingConsumerTemplate and >> move the messages to another queue, can I wrap this in a transaction >> given that there is no actual camel route? >> >> I'm using pollingConsumerTemplate as I want to control when/if I >> consume, but maybe there is an alternative way. >> > > You would need to wrap the code in a transaction yourself. And control > the begin / commit. > > > > >> Code looks a little like this so far.. >> >> =A0 =A0 =A0int max =3D 10; >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0while (true) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log.info("consuming.."); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0int inprogressQty =3D >> inprogressEndpoint.getExchanges().size(); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (inprogressQty < max) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log.info("There are {} it= ems inprogress", >> inprogressQty); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Exchange exchange =3D con= sumer.receive(1000); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (exchange !=3D null) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Object o =3D exch= ange.getIn().getBody(); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log.info("Got mes= sage: {}", o); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0producerTemplate.= send(inprogressEndpoint, exchange); >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else { >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0log.info("No mess= age"); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Thread.sleep(1000= ); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} catch (InterruptedExcep= tion e) { >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0e.printStackTrace= (); =A0//To change body of >> catch statement use File | Settings | File Templates. >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> >> >> >> Thanks, Tom > > > > -- > Claus Ibsen > ----------------- > FuseSource > Email: cibsen@fusesource.com > Web: http://fusesource.com > Twitter: davsclaus, fusenews > Blog: http://davsclaus.blogspot.com/ > Author of Camel in Action: http://www.manning.com/ibsen/ >