camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: JPA Component Behavior
Date Sat, 19 Jan 2013 08:09:15 GMT
Hi

We could possible enhance scheduled poll consumer to allow people to
set a max number of polls
http://camel.apache.org/polling-consumer.html

The timer component has a "repeatCount" option for that kind of use-case.
This will though still let the consumer be started and running, it
just prevents any further polling.


On Sat, Jan 19, 2013 at 1:42 AM, Chris Wolf <cwolf.algo@gmail.com> wrote:
> On Fri, Jan 18, 2013 at 12:01 PM, Gershaw, Geoffrey
> <geoffrey.gershaw@credit-suisse.com> wrote:
>> Hello once more,
>>
>>
>>
>>
>>
>> So I read in the documentation that the jpa component polls the db.
>> Kinda a poor man's queue. I had hoped that this behavior would be
>> configurable. I don't want to poll. I just want to retrieve the entities
>> 1 time. I would think the jpa component could do this.
>>
>>
>>
>> It doesn't appear so. Am I correct?
>>
>>
>>
>> I guess I shall create a custom bean to do the retrieval?
>>
>
> You don't need to.  I created an alternative
> PollingConsumerPollStrategy implementation,
> "OneShotPollingConsumerStrategy" (attached).
>
> The way it works is that you configure your JPA consumer endpoint with
> the options,
> "pollStrategy=#oneshotPoller&startScheduler=false" and make sure this
> route has it's
> id set.  When you create an instance of
> OneShotPollingConsumerStrategy, pass this
> route id string in the singel arg constructor, or call
> setDefaultRouteId(id) on the instance.
>
> To signal the JPA consumer route to perform it's
> one-time reading of the DB, change the route you want to drive this,
> by appending:
>
> .beanRef("oneshotPoller", "resumeJpaConsumer");
>
> ...to the end, so that when that route's processing completes, it will
> signal the
> JPA consuming route to read once.  This works by
> OneShotPollingConsumerStrategy.commit
> calling JpaConsumer.suspend().
>
> Upon the very first invocation of
> OneShotPollingConsumerStrategy.resumeJpaConsumer(), it
> will actually merely just start the scheduler, which stays running
> from then, on.  The second
> ans subsequent invocations of
> OneShotPollingConsumerStrategy.resumeJpaConsumer() will
> just call JpaConsumer.resume() and do nothing with the scheduler.
>
> There could be unintended consequences of calling
> JpaConsumer.suspend(), so I can't guarantee
> this solution is robust at this point.
>
> Sorry for the rough and lazy explanation.   If anyone finds it useful,
> I can document it better.
>
> Regards,
>
>     -Chris.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message