On Thu, Dec 1, 2011 at 10:10 AM, Tom Howe <[email protected]> wrote: > Hi Claus, > Thanks for your response - I've never done this before, would you be > able to point me to some example code? >
Camel uses the Spring Transaction API. So I would suggest to take a look at that. And how to programmatically being/commit/rollback transactions. For example Spring have a TransactionTemplate API you can use, which in fact will automatic begin / commit / rollback for you. In fact we do this in the TransactionErrorHandler in Camel. See https://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java > Thanks, Tom > > On Wed, Nov 30, 2011 at 7:53 AM, Claus Ibsen <[email protected]> wrote: >> On Wed, Nov 30, 2011 at 5:06 PM, Tom Howe <[email protected]> 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.. >>> >>> int max = 10; >>> >>> while (true) { >>> log.info("consuming.."); >>> int inprogressQty = >>> inprogressEndpoint.getExchanges().size(); >>> >>> if (inprogressQty < max) { >>> log.info("There are {} items inprogress", >>> inprogressQty); >>> Exchange exchange = consumer.receive(1000); >>> >>> if (exchange != null) { >>> Object o = exchange.getIn().getBody(); >>> log.info("Got message: {}", o); >>> >>> producerTemplate.send(inprogressEndpoint, >>> exchange); >>> >>> } else { >>> >>> log.info("No message"); >>> } >>> } else { >>> try { >>> Thread.sleep(1000); >>> } catch (InterruptedException e) { >>> e.printStackTrace(); //To change body of >>> catch statement use File | Settings | File Templates. >>> } >>> } >>> >>> } >>> >>> >>> >>> Thanks, Tom >> >> >> >> -- >> Claus Ibsen >> ----------------- >> FuseSource >> Email: [email protected] >> Web: http://fusesource.com >> Twitter: davsclaus, fusenews >> Blog: http://davsclaus.blogspot.com/ >> Author of Camel in Action: http://www.manning.com/ibsen/ >> -- Claus Ibsen ----------------- FuseSource Email: [email protected] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/
