camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Wolf <cwolf.a...@gmail.com>
Subject Re: JPA Component Behavior
Date Sat, 19 Jan 2013 00:42:57 GMT
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.

Mime
  • Unnamed multipart/mixed (inline, None, 0 bytes)
View raw message