You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Seb- <se...@gmail.com> on 2008/09/09 16:29:36 UTC

Routing depending on a Service

Hi,
I have problems imagining how camel can be used/integrated to route message
depending on return from a service call.
Let's say I have a file source endpoint that send messages to MyOwnRouter
which routes them depending on the return from a call to a service (whatever
may that be).
In the examples provided in various documentation for Routing, the routes
conditions are statically known at startup (when xpath(..)...)
Do I need to write an own component ? Would a bean be enough ? Can I use the
java DSL then ?
Thank you,
Regards,
Sébastien.
-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19393604.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
Hi James,
Thank you very much for your prompt faster-than-light reply!
That's exactly what I was looking for.
Just as a side note regarding Camel docs, in the FAQ comparison (ie
http://activemq.apache.org/camel/how-does-camel-compare-to-servicemix.html)
the newborn spring-integration is not compared (even if I have my own ideas
on the difference).
Thanks,
Regards,
Sébastien.


James.Strachan wrote:
> 
> 2008/9/9 Seb- <se...@gmail.com>:
>>
>> Hi,
>> I have problems imagining how camel can be used/integrated to route
>> message
>> depending on return from a service call.
>> Let's say I have a file source endpoint that send messages to MyOwnRouter
>> which routes them depending on the return from a call to a service
>> (whatever
>> may that be).
>> In the examples provided in various documentation for Routing, the routes
>> conditions are statically known at startup (when xpath(..)...)
>> Do I need to write an own component ? Would a bean be enough ? Can I use
>> the
>> java DSL then ?
> 
> You can dynamically invoke any expression and use the result of that
> expression to determine what endpoints a message goes to. So you can
> use things like a Dynamic Recipient List...
> 
> http://activemq.apache.org/camel/recipient-list.html
> 
> You can use any bean method to return the list of endpoints to send it
> to; using Java as the expression language if you prefer.
> 
> e.g.
> 
> from("activemq:Foo").recipientList().methodCall("someBean", "myMethod");
> 
> Then you can use any Java code you like to take the input message &
> headers and use any algorithm you can imagine to figure out where to
> send the message.
> http://activemq.apache.org/camel/bean-language.html
> http://activemq.apache.org/camel/bean-integration.html
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19394080.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
Hi James,
Thank you for your advise, really appreciated.
For the moment I used a processor prior to the methodCall() which set
properties to the Exchange.
Sébastien.


James.Strachan wrote:
> 
> 2008/9/12 Seb- <se...@gmail.com>:
>>
>> I thought about that, thing is I will know that at runtime only.
> 
> Any runtime knowledge can be wrapped up in a factory bean; or you can
> extract data from the message and use that to invoke a factory bean?
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19456968.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
I would have a Manager class with a method call(String bean, String...
parameters)
And this manager would be responsible for the real call to the bean (I don't
want to call the beans directly). So I would have something like this:

from("activemq:Foo").recipientList().methodCall("myManager", "call",
"beanX", "parameters", ...); 

And myManager would delegate the call to beanX.

Maybe there is a cleaner way to do this ? (Delegators?...)


James.Strachan wrote:
> 
> Could you give an example of some pseudocode you'd like to use?
> 
> 2008/9/12 James Strachan <ja...@gmail.com>:
>> 2008/9/12 Seb- <se...@gmail.com>:
>>>
>>> I thought about that, thing is I will know that at runtime only.
>>
>> Any runtime knowledge can be wrapped up in a factory bean; or you can
>> extract data from the message and use that to invoke a factory bean?
>>
>> --
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://open.iona.com
>>
> 
> 
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19452072.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by James Strachan <ja...@gmail.com>.
Could you give an example of some pseudocode you'd like to use?

2008/9/12 James Strachan <ja...@gmail.com>:
> 2008/9/12 Seb- <se...@gmail.com>:
>>
>> I thought about that, thing is I will know that at runtime only.
>
> Any runtime knowledge can be wrapped up in a factory bean; or you can
> extract data from the message and use that to invoke a factory bean?
>
> --
> James
> -------
> http://macstrac.blogspot.com/
>
> Open Source Integration
> http://open.iona.com
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Routing depending on a Service

Posted by James Strachan <ja...@gmail.com>.
2008/9/12 Seb- <se...@gmail.com>:
>
> I thought about that, thing is I will know that at runtime only.

Any runtime knowledge can be wrapped up in a factory bean; or you can
extract data from the message and use that to invoke a factory bean?

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
I thought about that, thing is I will know that at runtime only.


James.Strachan wrote:
> 
> 2008/9/11 Seb- <se...@gmail.com>:
>>
>> Hi Hadrian,
>> Sure I have access to Exchange/Body/...
>> But I was looking for something like this:
>>
>> from("activemq:Foo").recipientList().methodCall("someBean", "myMethod",
>> "some", "parameters", ...);
> 
> Why not use Spring to create an instance of your bean injected with
> whatever parameters you want.
> 
> from("activemq:Foo").recipientList().methodCall("someBeanWithParams1",
> "myMethod");
> from("activemq:Foo").recipientList().methodCall("someBeanWithParams2",
> "myMethod");
> 
> 
> etc. i.e. you just need to create a name for each set of parameters
> you need. Or create a FactoryBean to inject custom properties
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19451800.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by James Strachan <ja...@gmail.com>.
2008/9/11 Seb- <se...@gmail.com>:
>
> Hi Hadrian,
> Sure I have access to Exchange/Body/...
> But I was looking for something like this:
>
> from("activemq:Foo").recipientList().methodCall("someBean", "myMethod",
> "some", "parameters", ...);

Why not use Spring to create an instance of your bean injected with
whatever parameters you want.

from("activemq:Foo").recipientList().methodCall("someBeanWithParams1",
"myMethod");
from("activemq:Foo").recipientList().methodCall("someBeanWithParams2",
"myMethod");


etc. i.e. you just need to create a name for each set of parameters
you need. Or create a FactoryBean to inject custom properties
-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com

Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
Hi Hadrian,
Sure I have access to Exchange/Body/...
But I was looking for something like this:

from("activemq:Foo").recipientList().methodCall("someBean", "myMethod",
"some", "parameters", ...);

Thanks,
Sébastien.


Hadrian Zbarcea wrote:
> 
> Hi,
> 
> Sure you can:
> 
> 
> Did you look at:
> http://activemq.apache.org/camel/bean-integration.html
> 
> The bean has access to the Exchange, so all the arguments should be  
> there, either in the header or the body.
> 
> What kind of parameters are you thinking of?
> 
> Cheers,
> Hadrian
> 
> On Sep 11, 2008, at 10:36 AM, Seb- wrote:
> 
>>
>> Hi,
>> I have a subsidiary question: Is it possible to pass parameter to  
>> the bean
>> method called ?
>> Thanks,
>> Sébastien.
>>
>>
>> James.Strachan wrote:
>>>
>>> 2008/9/9 Seb- <se...@gmail.com>:
>>>>
>>>> Hi,
>>>> I have problems imagining how camel can be used/integrated to route
>>>> message
>>>> depending on return from a service call.
>>>> Let's say I have a file source endpoint that send messages to  
>>>> MyOwnRouter
>>>> which routes them depending on the return from a call to a service
>>>> (whatever
>>>> may that be).
>>>> In the examples provided in various documentation for Routing, the  
>>>> routes
>>>> conditions are statically known at startup (when xpath(..)...)
>>>> Do I need to write an own component ? Would a bean be enough ? Can  
>>>> I use
>>>> the
>>>> java DSL then ?
>>>
>>> You can dynamically invoke any expression and use the result of that
>>> expression to determine what endpoints a message goes to. So you can
>>> use things like a Dynamic Recipient List...
>>>
>>> http://activemq.apache.org/camel/recipient-list.html
>>>
>>> You can use any bean method to return the list of endpoints to send  
>>> it
>>> to; using Java as the expression language if you prefer.
>>>
>>> e.g.
>>>
>>> from("activemq:Foo").recipientList().methodCall("someBean",  
>>> "myMethod");
>>>
>>> Then you can use any Java code you like to take the input message &
>>> headers and use any algorithm you can imagine to figure out where to
>>> send the message.
>>> http://activemq.apache.org/camel/bean-language.html
>>> http://activemq.apache.org/camel/bean-integration.html
>>>
>>> -- 
>>> James
>>> -------
>>> http://macstrac.blogspot.com/
>>>
>>> Open Source Integration
>>> http://open.iona.com
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19436281.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19437717.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by Hadrian Zbarcea <hz...@gmail.com>.
Hi,

Sure you can:


Did you look at:
http://activemq.apache.org/camel/bean-integration.html

The bean has access to the Exchange, so all the arguments should be  
there, either in the header or the body.

What kind of parameters are you thinking of?

Cheers,
Hadrian

On Sep 11, 2008, at 10:36 AM, Seb- wrote:

>
> Hi,
> I have a subsidiary question: Is it possible to pass parameter to  
> the bean
> method called ?
> Thanks,
> Sébastien.
>
>
> James.Strachan wrote:
>>
>> 2008/9/9 Seb- <se...@gmail.com>:
>>>
>>> Hi,
>>> I have problems imagining how camel can be used/integrated to route
>>> message
>>> depending on return from a service call.
>>> Let's say I have a file source endpoint that send messages to  
>>> MyOwnRouter
>>> which routes them depending on the return from a call to a service
>>> (whatever
>>> may that be).
>>> In the examples provided in various documentation for Routing, the  
>>> routes
>>> conditions are statically known at startup (when xpath(..)...)
>>> Do I need to write an own component ? Would a bean be enough ? Can  
>>> I use
>>> the
>>> java DSL then ?
>>
>> You can dynamically invoke any expression and use the result of that
>> expression to determine what endpoints a message goes to. So you can
>> use things like a Dynamic Recipient List...
>>
>> http://activemq.apache.org/camel/recipient-list.html
>>
>> You can use any bean method to return the list of endpoints to send  
>> it
>> to; using Java as the expression language if you prefer.
>>
>> e.g.
>>
>> from("activemq:Foo").recipientList().methodCall("someBean",  
>> "myMethod");
>>
>> Then you can use any Java code you like to take the input message &
>> headers and use any algorithm you can imagine to figure out where to
>> send the message.
>> http://activemq.apache.org/camel/bean-language.html
>> http://activemq.apache.org/camel/bean-integration.html
>>
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>>
>> Open Source Integration
>> http://open.iona.com
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19436281.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Routing depending on a Service

Posted by Seb- <se...@gmail.com>.
Hi,
I have a subsidiary question: Is it possible to pass parameter to the bean
method called ?
Thanks,
Sébastien. 


James.Strachan wrote:
> 
> 2008/9/9 Seb- <se...@gmail.com>:
>>
>> Hi,
>> I have problems imagining how camel can be used/integrated to route
>> message
>> depending on return from a service call.
>> Let's say I have a file source endpoint that send messages to MyOwnRouter
>> which routes them depending on the return from a call to a service
>> (whatever
>> may that be).
>> In the examples provided in various documentation for Routing, the routes
>> conditions are statically known at startup (when xpath(..)...)
>> Do I need to write an own component ? Would a bean be enough ? Can I use
>> the
>> java DSL then ?
> 
> You can dynamically invoke any expression and use the result of that
> expression to determine what endpoints a message goes to. So you can
> use things like a Dynamic Recipient List...
> 
> http://activemq.apache.org/camel/recipient-list.html
> 
> You can use any bean method to return the list of endpoints to send it
> to; using Java as the expression language if you prefer.
> 
> e.g.
> 
> from("activemq:Foo").recipientList().methodCall("someBean", "myMethod");
> 
> Then you can use any Java code you like to take the input message &
> headers and use any algorithm you can imagine to figure out where to
> send the message.
> http://activemq.apache.org/camel/bean-language.html
> http://activemq.apache.org/camel/bean-integration.html
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://open.iona.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Routing-depending-on-a-Service-tp19393604s22882p19436281.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Routing depending on a Service

Posted by James Strachan <ja...@gmail.com>.
2008/9/9 Seb- <se...@gmail.com>:
>
> Hi,
> I have problems imagining how camel can be used/integrated to route message
> depending on return from a service call.
> Let's say I have a file source endpoint that send messages to MyOwnRouter
> which routes them depending on the return from a call to a service (whatever
> may that be).
> In the examples provided in various documentation for Routing, the routes
> conditions are statically known at startup (when xpath(..)...)
> Do I need to write an own component ? Would a bean be enough ? Can I use the
> java DSL then ?

You can dynamically invoke any expression and use the result of that
expression to determine what endpoints a message goes to. So you can
use things like a Dynamic Recipient List...

http://activemq.apache.org/camel/recipient-list.html

You can use any bean method to return the list of endpoints to send it
to; using Java as the expression language if you prefer.

e.g.

from("activemq:Foo").recipientList().methodCall("someBean", "myMethod");

Then you can use any Java code you like to take the input message &
headers and use any algorithm you can imagine to figure out where to
send the message.
http://activemq.apache.org/camel/bean-language.html
http://activemq.apache.org/camel/bean-integration.html

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com