camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Howe <tomh...@artcore.com>
Subject Re: Transactions with PollingConsumerTemplate/producerTemplate
Date Thu, 01 Dec 2011 09:10:58 GMT
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 <claus.ibsen@gmail.com> wrote:
> On Wed, Nov 30, 2011 at 5:06 PM, Tom Howe <tomhowe@artcore.com> 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: 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/
>

Mime
View raw message