You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Mark Webb <el...@gmail.com> on 2011/03/31 18:54:29 UTC

polling database

I want to create a route that will query a database for new rows
periodically.  If a new row is found I would like to put the
information from that row into the route for processing.  I have been
looking at the timer and quartz components and can't seem to get
either one to fit quite right with me requirement.

Is there another Camel component that will do this?  I have looked
through the Camel book and found ScheduledPollConsumer, but that just
looks like I would need to add in my own "sleep".

I tried looking at the unit tests in
/camel/trunk/camel-camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer
and could not find anything that fits either.

Any other suggestions?

Thanks,
Mark

Re: polling database

Posted by Michael Dewitte <mi...@gmail.com>.
Hi,

why don't timer component fit your requirements ?

from("timer://pollTheDatabase?delay=30000").to("mbatis:selectAllAccounts").to("activemq:queue:allAccounts");


would execute the query configured un mybatis every 30 seconds... and put
the result on the queue allAccounts...
You can either process the result as a list or have each individual row sent
further in the route...
Of course, you have to have a way to mark the rows as processed. This can be
done with the consumer.onConsume parameter.

Hope it helps,

Mike


2011/3/31 Mark Webb <el...@gmail.com>

> I want to create a route that will query a database for new rows
> periodically.  If a new row is found I would like to put the
> information from that row into the route for processing.  I have been
> looking at the timer and quartz components and can't seem to get
> either one to fit quite right with me requirement.
>
> Is there another Camel component that will do this?  I have looked
> through the Camel book and found ScheduledPollConsumer, but that just
> looks like I would need to add in my own "sleep".
>
> I tried looking at the unit tests in
>
> /camel/trunk/camel-camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer
> and could not find anything that fits either.
>
> Any other suggestions?
>
> Thanks,
> Mark
>

Re: polling database

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

The JPA can also do this
http://camel.apache.org/jpa

It will delete the record after it has been processed. If you want to
customize this you can set the option to false and use @Consumed in
the Entity pojo and that method would be invoked. Check the source
code of camel-jpa for examples.

On Thu, Mar 31, 2011 at 6:54 PM, Mark Webb <el...@gmail.com> wrote:
> I want to create a route that will query a database for new rows
> periodically.  If a new row is found I would like to put the
> information from that row into the route for processing.  I have been
> looking at the timer and quartz components and can't seem to get
> either one to fit quite right with me requirement.
>
> Is there another Camel component that will do this?  I have looked
> through the Camel book and found ScheduledPollConsumer, but that just
> looks like I would need to add in my own "sleep".
>
> I tried looking at the unit tests in
> /camel/trunk/camel-camel/trunk/camel-core/src/test/java/org/apache/camel/component/timer
> and could not find anything that fits either.
>
> Any other suggestions?
>
> Thanks,
> Mark
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
CamelOne 2011: http://fusesource.com/camelone2011/
Twitter: davsclaus
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Re: polling database

Posted by Christian Müller <ch...@gmail.com>.
Hello Mark!

Sample taken from the camel-jdbc wiki page [1]:

from("timer://foo?period=60000").setBody(constant("select * from
customer")).to("jdbc:testdb").to("activemq:queue:customers");


[1] http://camel.apache.org/jdbc.html

Cheers,
Christian