You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by lassesvestergaard <la...@gmail.com> on 2013/09/04 18:53:15 UTC

Conceptual understanding of altering routes runtime

Hi all.

This is a spinoff of a previous post:
http://camel.465427.n5.nabble.com/Change-timer-runtime-td5738484.html

I decided to start a new thread, because I think this question is of a more
general character.

First of all, I ran into a problem regarding how to update a camel route
runtime. My concrete problem is that I can't figure out how to update a sql
query runtime. If I, for instance, want to have a query that fetches the
first 3000 records of a table, on the first cycle of the camel route (let's
say I use a timer to "fire" the route). In the next cycle, I want to fetch
from record 3001 to 6000. I simply can't get my head around this problem,
which is extremely simple in regular java. My conclusion from this is, that
I have some fundamental misconceptions of what Apache camel is, and therefor
I want to use this thread to discuss runtime altering of routes.

For starters: As I understand, an Exchange is a entity that only exists
within a single cycle of a route. This means that I can't use the Exchange
object to save variables that I can use in the next cycle of the route. This
further means that I can't use Exchange to alter configurations of a
component - ex. I can't use it for giving the timer component a different
period and I can't use it for altering variables in a sql query.

Besides this, it seems that you can only write your route once, and the
first time it's run, all component configurations are set - they cannot be
altered from within the route it self. In my specific case, I have tried to
put java variables into my sql query (having them assigned as class scoped
attributes). In my route I have a Processor (see referenced thread at the
top), and in that I have altered the java attributes. This seems to work
fine, but the sql query doesn't get updated with the new value of my java
variable. 

Furthermore, I haven't been able to find any good examples, that show how to
alter the route configurations runtime (actually the configurations of each
component in a route).

Since I can't Google the problem away, I conclude that I have issues on the
conceptual understanding of Camel. So, could someone please clarify how to
understand runtime alterings of routes, and it would be even better if you
have some concrete coding examples.

I have chosen to use the java DSL approach instead of Spring.

Best regards

Lasse Vestergaard



--
View this message in context: http://camel.465427.n5.nabble.com/Conceptual-understanding-of-altering-routes-runtime-tp5738697.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Conceptual understanding of altering routes runtime

Posted by Mike Oxford <mo...@gmail.com>.
I believe you can "synthesize" with a dynamic-router.

Get first chunk, route to processor-route.  When that route completes, it
will head back to dynamic-router with the same Exchange.  If that Exchange
has a property which says "this SQL connection" and a property which says
"this starting number" (or, if you have the handle to the SQL connection,
using a cursor) it may work for you.

G'luck...

-mox



On Thu, Sep 5, 2013 at 1:26 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Also you dont have to use Camel routes.
> Sometimes just use Camel as a client API and use ProducerTemplate /
> ConsumerTemplate to use the Camel components can be fine.
>
>
>
> On Wed, Sep 4, 2013 at 6:53 PM, lassesvestergaard
> <la...@gmail.com> wrote:
> > Hi all.
> >
> > This is a spinoff of a previous post:
> > http://camel.465427.n5.nabble.com/Change-timer-runtime-td5738484.html
> >
> > I decided to start a new thread, because I think this question is of a
> more
> > general character.
> >
> > First of all, I ran into a problem regarding how to update a camel route
> > runtime. My concrete problem is that I can't figure out how to update a
> sql
> > query runtime. If I, for instance, want to have a query that fetches the
> > first 3000 records of a table, on the first cycle of the camel route
> (let's
> > say I use a timer to "fire" the route). In the next cycle, I want to
> fetch
> > from record 3001 to 6000. I simply can't get my head around this problem,
> > which is extremely simple in regular java. My conclusion from this is,
> that
> > I have some fundamental misconceptions of what Apache camel is, and
> therefor
> > I want to use this thread to discuss runtime altering of routes.
> >
> > For starters: As I understand, an Exchange is a entity that only exists
> > within a single cycle of a route. This means that I can't use the
> Exchange
> > object to save variables that I can use in the next cycle of the route.
> This
> > further means that I can't use Exchange to alter configurations of a
> > component - ex. I can't use it for giving the timer component a different
> > period and I can't use it for altering variables in a sql query.
> >
> > Besides this, it seems that you can only write your route once, and the
> > first time it's run, all component configurations are set - they cannot
> be
> > altered from within the route it self. In my specific case, I have tried
> to
> > put java variables into my sql query (having them assigned as class
> scoped
> > attributes). In my route I have a Processor (see referenced thread at the
> > top), and in that I have altered the java attributes. This seems to work
> > fine, but the sql query doesn't get updated with the new value of my java
> > variable.
> >
> > Furthermore, I haven't been able to find any good examples, that show
> how to
> > alter the route configurations runtime (actually the configurations of
> each
> > component in a route).
> >
> > Since I can't Google the problem away, I conclude that I have issues on
> the
> > conceptual understanding of Camel. So, could someone please clarify how
> to
> > understand runtime alterings of routes, and it would be even better if
> you
> > have some concrete coding examples.
> >
> > I have chosen to use the java DSL approach instead of Spring.
> >
> > Best regards
> >
> > Lasse Vestergaard
> >
> >
> >
> > --
> > View this message in context:
> http://camel.465427.n5.nabble.com/Conceptual-understanding-of-altering-routes-runtime-tp5738697.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Conceptual understanding of altering routes runtime

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

Also you dont have to use Camel routes.
Sometimes just use Camel as a client API and use ProducerTemplate /
ConsumerTemplate to use the Camel components can be fine.



On Wed, Sep 4, 2013 at 6:53 PM, lassesvestergaard
<la...@gmail.com> wrote:
> Hi all.
>
> This is a spinoff of a previous post:
> http://camel.465427.n5.nabble.com/Change-timer-runtime-td5738484.html
>
> I decided to start a new thread, because I think this question is of a more
> general character.
>
> First of all, I ran into a problem regarding how to update a camel route
> runtime. My concrete problem is that I can't figure out how to update a sql
> query runtime. If I, for instance, want to have a query that fetches the
> first 3000 records of a table, on the first cycle of the camel route (let's
> say I use a timer to "fire" the route). In the next cycle, I want to fetch
> from record 3001 to 6000. I simply can't get my head around this problem,
> which is extremely simple in regular java. My conclusion from this is, that
> I have some fundamental misconceptions of what Apache camel is, and therefor
> I want to use this thread to discuss runtime altering of routes.
>
> For starters: As I understand, an Exchange is a entity that only exists
> within a single cycle of a route. This means that I can't use the Exchange
> object to save variables that I can use in the next cycle of the route. This
> further means that I can't use Exchange to alter configurations of a
> component - ex. I can't use it for giving the timer component a different
> period and I can't use it for altering variables in a sql query.
>
> Besides this, it seems that you can only write your route once, and the
> first time it's run, all component configurations are set - they cannot be
> altered from within the route it self. In my specific case, I have tried to
> put java variables into my sql query (having them assigned as class scoped
> attributes). In my route I have a Processor (see referenced thread at the
> top), and in that I have altered the java attributes. This seems to work
> fine, but the sql query doesn't get updated with the new value of my java
> variable.
>
> Furthermore, I haven't been able to find any good examples, that show how to
> alter the route configurations runtime (actually the configurations of each
> component in a route).
>
> Since I can't Google the problem away, I conclude that I have issues on the
> conceptual understanding of Camel. So, could someone please clarify how to
> understand runtime alterings of routes, and it would be even better if you
> have some concrete coding examples.
>
> I have chosen to use the java DSL approach instead of Spring.
>
> Best regards
>
> Lasse Vestergaard
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Conceptual-understanding-of-altering-routes-runtime-tp5738697.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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

Re: Conceptual understanding of altering routes runtime

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

You can just use a java bean to query the database to get the rows you want.

You can then call the bean from a Camel route, and trigger the route
using a timer etc if you want.

in your bean you can keep state and keep track of the row number
interval to fetch.

And from your bean you can use ProducerTemplate / POJO producing if
you want to use a Camel component for the database access.

http://camel.apache.org/producertemplate.html
http://camel.apache.org/pojo-messaging-example.html
http://camel.apache.org/bean

You dont have to use Camel for everything. Writing some logic in java
code is *still* encouraged and allowed :) Its what best for you to do
and maintain, understand, etc.



On Wed, Sep 4, 2013 at 6:53 PM, lassesvestergaard
<la...@gmail.com> wrote:
> Hi all.
>
> This is a spinoff of a previous post:
> http://camel.465427.n5.nabble.com/Change-timer-runtime-td5738484.html
>
> I decided to start a new thread, because I think this question is of a more
> general character.
>
> First of all, I ran into a problem regarding how to update a camel route
> runtime. My concrete problem is that I can't figure out how to update a sql
> query runtime. If I, for instance, want to have a query that fetches the
> first 3000 records of a table, on the first cycle of the camel route (let's
> say I use a timer to "fire" the route). In the next cycle, I want to fetch
> from record 3001 to 6000. I simply can't get my head around this problem,
> which is extremely simple in regular java. My conclusion from this is, that
> I have some fundamental misconceptions of what Apache camel is, and therefor
> I want to use this thread to discuss runtime altering of routes.
>
> For starters: As I understand, an Exchange is a entity that only exists
> within a single cycle of a route. This means that I can't use the Exchange
> object to save variables that I can use in the next cycle of the route. This
> further means that I can't use Exchange to alter configurations of a
> component - ex. I can't use it for giving the timer component a different
> period and I can't use it for altering variables in a sql query.
>
> Besides this, it seems that you can only write your route once, and the
> first time it's run, all component configurations are set - they cannot be
> altered from within the route it self. In my specific case, I have tried to
> put java variables into my sql query (having them assigned as class scoped
> attributes). In my route I have a Processor (see referenced thread at the
> top), and in that I have altered the java attributes. This seems to work
> fine, but the sql query doesn't get updated with the new value of my java
> variable.
>
> Furthermore, I haven't been able to find any good examples, that show how to
> alter the route configurations runtime (actually the configurations of each
> component in a route).
>
> Since I can't Google the problem away, I conclude that I have issues on the
> conceptual understanding of Camel. So, could someone please clarify how to
> understand runtime alterings of routes, and it would be even better if you
> have some concrete coding examples.
>
> I have chosen to use the java DSL approach instead of Spring.
>
> Best regards
>
> Lasse Vestergaard
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Conceptual-understanding-of-altering-routes-runtime-tp5738697.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



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