You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Tarun Kumar <ag...@gmail.com> on 2013/05/23 12:26:12 UTC

Dynamic Route in camel

1. In my routes, output exchange of first endpoint gives me one id that i
use in .to() to form endpoint url. So, basically my .to() url will look
like:

abc.com/cid

This cid i get from out exchange of first endpoint. How can i set that?

2. in camel dynamic router, i saw :


from("direct:start")
    // use a bean as the dynamic router
.dynamicRouter(method(DynamicRouterTest.class, "slip"));

public String slip(String body) {
    bodies.add(body);
    invoked++;

    if (invoked == 1) {
        return "mock:a";
    } else if (invoked == 2) {
        return "mock:b,mock:c";
    } else if (invoked == 3) {
        return "direct:foo";
    } else if (invoked == 4) {
        return "mock:result";
    }

    // no more so return null    return null;
}


But, here my question is : who will set body (method parameter) in slip method?


Thanks,

Tarun

Re: Dynamic Route in camel

Posted by Tarun Kumar <ag...@gmail.com>.
Alternatively, .bean(obj, methodName) also works :-)
One more question related to this:

If i try .bean(className, methodName('a', 'b')) : it calls method
methodName of class className with method parameters 'a' and 'b'. However,
if i want value of method variables to come from class variables, how can i
do that?

what i mean is :
class abc extends RouteBuilder {
  private string str1 = 'a';
  private string str2 = 'b';
.....
.....
to().bean(className, methodName(str1, str2)).end();

i get str1 and str2 classes not found exception. How can i pass str1 and
str2 values as method parameters without actually hardcoding them?


On Thu, May 30, 2013 at 2:02 PM, Claus Ibsen <cl...@gmail.com> wrote:

> If the bean is enlisted in the registry so Camel can look it up, then
> you can call any bean you want.
>
>
> On Thu, May 30, 2013 at 8:15 AM, Tarun Kumar <ag...@gmail.com>
> wrote:
> > Hey Claus,
> >
> > What if i want to call non static method with object of that bean i have
> in
> > the caller class? Is there any way to do that?
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> 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
>

Re: Dynamic Route in camel

Posted by Claus Ibsen <cl...@gmail.com>.
If the bean is enlisted in the registry so Camel can look it up, then
you can call any bean you want.


On Thu, May 30, 2013 at 8:15 AM, Tarun Kumar <ag...@gmail.com> wrote:
> Hey Claus,
>
> What if i want to call non static method with object of that bean i have in
> the caller class? Is there any way to do that?



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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

Re: Dynamic Route in camel

Posted by Tarun Kumar <ag...@gmail.com>.
Hey Claus,

What if i want to call non static method with object of that bean i have in
the caller class? Is there any way to do that?

Re: Dynamic Route in camel

Posted by Claus Ibsen <cl...@gmail.com>.
It can also call non static methods, if the bean has a default no-arg
constructor.

Or if you have enlisted a bean instance in the registry, and refer to
the bean id of this instance instead.

On Tue, May 28, 2013 at 9:47 AM, Tarun Kumar <ag...@gmail.com> wrote:
> Hi Claus,
>
> Thanks for the reply. Bean-integration works only if method i am calling is
> public static. What if i want to call non-static method?
>
>
> On Sun, May 26, 2013 at 2:02 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Ad 1)
>> See this FAQ
>> http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html
>>
>>
>> Ad 2)
>> See about bean integration and bean parameter binding at
>> http://camel.apache.org/bean-integration.html
>>
>> And about the bean language
>> http://camel.apache.org/bean-language.html
>>
>> On Thu, May 23, 2013 at 12:26 PM, Tarun Kumar <ag...@gmail.com>
>> wrote:
>> > 1. In my routes, output exchange of first endpoint gives me one id that i
>> > use in .to() to form endpoint url. So, basically my .to() url will look
>> > like:
>> >
>> > abc.com/cid
>> >
>> > This cid i get from out exchange of first endpoint. How can i set that?
>> >
>> > 2. in camel dynamic router, i saw :
>> >
>> >
>> > from("direct:start")
>> >     // use a bean as the dynamic router
>> > .dynamicRouter(method(DynamicRouterTest.class, "slip"));
>> >
>> > public String slip(String body) {
>> >     bodies.add(body);
>> >     invoked++;
>> >
>> >     if (invoked == 1) {
>> >         return "mock:a";
>> >     } else if (invoked == 2) {
>> >         return "mock:b,mock:c";
>> >     } else if (invoked == 3) {
>> >         return "direct:foo";
>> >     } else if (invoked == 4) {
>> >         return "mock:result";
>> >     }
>> >
>> >     // no more so return null    return null;
>> > }
>> >
>> >
>> > But, here my question is : who will set body (method parameter) in slip
>> method?
>> >
>> >
>> > Thanks,
>> >
>> > Tarun
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> www.camelone.org: The open source integration conference.
>>
>> 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
>>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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

Re: Dynamic Route in camel

Posted by Tarun Kumar <ag...@gmail.com>.
Hi Claus,

Thanks for the reply. Bean-integration works only if method i am calling is
public static. What if i want to call non-static method?


On Sun, May 26, 2013 at 2:02 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Ad 1)
> See this FAQ
> http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html
>
>
> Ad 2)
> See about bean integration and bean parameter binding at
> http://camel.apache.org/bean-integration.html
>
> And about the bean language
> http://camel.apache.org/bean-language.html
>
> On Thu, May 23, 2013 at 12:26 PM, Tarun Kumar <ag...@gmail.com>
> wrote:
> > 1. In my routes, output exchange of first endpoint gives me one id that i
> > use in .to() to form endpoint url. So, basically my .to() url will look
> > like:
> >
> > abc.com/cid
> >
> > This cid i get from out exchange of first endpoint. How can i set that?
> >
> > 2. in camel dynamic router, i saw :
> >
> >
> > from("direct:start")
> >     // use a bean as the dynamic router
> > .dynamicRouter(method(DynamicRouterTest.class, "slip"));
> >
> > public String slip(String body) {
> >     bodies.add(body);
> >     invoked++;
> >
> >     if (invoked == 1) {
> >         return "mock:a";
> >     } else if (invoked == 2) {
> >         return "mock:b,mock:c";
> >     } else if (invoked == 3) {
> >         return "direct:foo";
> >     } else if (invoked == 4) {
> >         return "mock:result";
> >     }
> >
> >     // no more so return null    return null;
> > }
> >
> >
> > But, here my question is : who will set body (method parameter) in slip
> method?
> >
> >
> > Thanks,
> >
> > Tarun
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> 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
>

Re: Dynamic Route in camel

Posted by Claus Ibsen <cl...@gmail.com>.
Ad 1)
See this FAQ
http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html


Ad 2)
See about bean integration and bean parameter binding at
http://camel.apache.org/bean-integration.html

And about the bean language
http://camel.apache.org/bean-language.html

On Thu, May 23, 2013 at 12:26 PM, Tarun Kumar <ag...@gmail.com> wrote:
> 1. In my routes, output exchange of first endpoint gives me one id that i
> use in .to() to form endpoint url. So, basically my .to() url will look
> like:
>
> abc.com/cid
>
> This cid i get from out exchange of first endpoint. How can i set that?
>
> 2. in camel dynamic router, i saw :
>
>
> from("direct:start")
>     // use a bean as the dynamic router
> .dynamicRouter(method(DynamicRouterTest.class, "slip"));
>
> public String slip(String body) {
>     bodies.add(body);
>     invoked++;
>
>     if (invoked == 1) {
>         return "mock:a";
>     } else if (invoked == 2) {
>         return "mock:b,mock:c";
>     } else if (invoked == 3) {
>         return "direct:foo";
>     } else if (invoked == 4) {
>         return "mock:result";
>     }
>
>     // no more so return null    return null;
> }
>
>
> But, here my question is : who will set body (method parameter) in slip method?
>
>
> Thanks,
>
> Tarun



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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