You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nkrust <sa...@gmail.com> on 2010/12/02 23:10:06 UTC

Hor to route using objects

Hi,

I'm trying to do a POC on Content Based Routing based on camel.
>From what ever literature that I've seen so far I only see routing happening
from files, queues etc. But I've not seen any example where I can route
based on a particular property of a ValueObject.

Is it possible, if so how can it be implemented?
-- 
View this message in context: http://camel.465427.n5.nabble.com/Hor-to-route-using-objects-tp3290076p3290076.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Hor to route using objects

Posted by Claus Straube <cl...@catify.com>.
Hi,

I'm sure will not get a java object back as http response ;) You should 
read this documentation http://camel.apache.org/http.html and perhaps 
write a simple test to check out how your response looks like. Then you 
can convert it to a java bean or wath ever you want.

Best regards - Claus

On 06.12.2010 14:29, nkrust wrote:
>
> claus.straube wrote:
>> Hi.
>>
>> You can use camel in your java class like this:
>>
>> @EndpointInject(uri="direct:start")
>>
>> protected ProducerTemplate start;
>>
>> ...
>>
>> start.sendBody(body);
>>
>>
>> The route should look like this:
>>
>> from("direct:start")  // This is a java class and the message is a java
>> object.
>> .choice()
>> .when(simple("${body.ID}=='A'")).to("serverX")
>> .when(simple("${body.ID}=='B'")).to("serverY")
>> .otherwise().to("serverZ")
>> .end();
>>
>> For me it's not clear, what do you mean by server? Are the destination
>> classes are in your context (e.g. spring)? IF yes ist could look like:
>>
>> from("direct:start")  // This is a java class and the message is a java
>> object.
>> .choice()
>> .when(simple("${body.ID}=='A'")).to("bean:x")
>> .when(simple("${body.ID}=='B'")).to("bean:y")
>> .otherwise().to("bean:z")
>> .end();
>>
>> While x, y, z are the spring ids...
>>
>>
> Hi Claus,
>
> "serverX", serverY... are not beans but URL's of routing servers, so this is
> how I'm using it and I hope it is correct:
> when(simple("${body.ID}=='A'")).to("http://serverX.com/contextPath").
>
> Now my question was, after I send a message to serverX, how do I receive the
> response back. The response in this case will be an object.


Re: Hor to route using objects

Posted by nkrust <sa...@gmail.com>.

claus.straube wrote:
> 
> Hi.
> 
> You can use camel in your java class like this:
> 
> @EndpointInject(uri="direct:start")
> 
> protected ProducerTemplate start;
> 
> ...
> 
> start.sendBody(body);
> 
> 
> The route should look like this:
> 
> from("direct:start")  // This is a java class and the message is a java
> object.
> .choice()
> .when(simple("${body.ID}=='A'")).to("serverX")
> .when(simple("${body.ID}=='B'")).to("serverY")
> .otherwise().to("serverZ")
> .end();
> 
> For me it's not clear, what do you mean by server? Are the destination 
> classes are in your context (e.g. spring)? IF yes ist could look like:
> 
> from("direct:start")  // This is a java class and the message is a java
> object.
> .choice()
> .when(simple("${body.ID}=='A'")).to("bean:x")
> .when(simple("${body.ID}=='B'")).to("bean:y")
> .otherwise().to("bean:z")
> .end();
> 
> While x, y, z are the spring ids...
> 
> 

Hi Claus,

"serverX", serverY... are not beans but URL's of routing servers, so this is
how I'm using it and I hope it is correct:
when(simple("${body.ID}=='A'")).to("http://serverX.com/contextPath").

Now my question was, after I send a message to serverX, how do I receive the
response back. The response in this case will be an object.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Hor-to-route-using-objects-tp3290076p3294008.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Hor to route using objects

Posted by Claus Straube <cl...@catify.com>.
Hi.

You can use camel in your java class like this:

@EndpointInject(uri="direct:start")

protected ProducerTemplate start;

...

start.sendBody(body);


The route should look like this:

from("direct:start")  // This is a java class and the message is a java object.
.choice()
.when(simple("${body.ID}=='A'")).to("serverX")
.when(simple("${body.ID}=='B'")).to("serverY")
.otherwise().to("serverZ")
.end();

For me it's not clear, what do you mean by server? Are the destination 
classes are in your context (e.g. spring)? IF yes ist could look like:

from("direct:start")  // This is a java class and the message is a java object.
.choice()
.when(simple("${body.ID}=='A'")).to("bean:x")
.when(simple("${body.ID}=='B'")).to("bean:y")
.otherwise().to("bean:z")
.end();

While x, y, z are the spring ids...

Best regards - Claus

On 03.12.2010 09:59, nkrust wrote:
> Hi,
>
> The consumer is a java class and I'm passing a java VO to the producer(s)
> depending on certain parameters in the VO.
>
> from(endPoint)  // This is a java class and the message is a java object.
> .choice()
> .when(simple("${body.ID}=='A'")).to("serverX")
> .when(simple("${body.ID}=='B'")).to("serverY")
> .otherwise().to("serverZ")
> .end();
>
> I wanted to know how I can use a java class as consumer with VO as the
> message. Also how the response which will again be a java object can be used
> by the consumer.
> I understand that camel is designed to work between a wide variety of
> components and using from a java class is not really smart thing to do, but
> I'm just doin a POC to see what all can be done.
> Any insight appretiated.


-- 
claus straube
__________________________________________

phone    +49-89-38157419
mobile   +49-176-49673717
web      http://www.catify.com
office   6. floor, heßstr. 56, 80798 munich
__________________________________________

catify | claus straube, sebastian münz


Re: Hor to route using objects

Posted by nkrust <sa...@gmail.com>.
Hi,

The consumer is a java class and I'm passing a java VO to the producer(s)
depending on certain parameters in the VO.

from(endPoint)  // This is a java class and the message is a java object.
.choice()
.when(simple("${body.ID}=='A'")).to("serverX")
.when(simple("${body.ID}=='B'")).to("serverY")
.otherwise().to("serverZ")
.end();

I wanted to know how I can use a java class as consumer with VO as the
message. Also how the response which will again be a java object can be used
by the consumer.
I understand that camel is designed to work between a wide variety of
components and using from a java class is not really smart thing to do, but
I'm just doin a POC to see what all can be done.
Any insight appretiated.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Hor-to-route-using-objects-tp3290076p3290569.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Hor to route using objects

Posted by Claus Straube <cl...@catify.com>.
You have to differ between consumers (from), producers (to) and the 
route semantic like a content based routing. For me it's not clear what 
you want to know. The from uris are depending on the consumer component 
you want to use (http://camel.apache.org/components.html) as well as the 
producers... Claus showed you how to build a content based router (that 
was your initial question) - if you  have questions about from() / to(), 
you should tell us what component you want to use (where come your 
messages from, where will they go?). What are the consumers on the 
different servers? Is it a Webservice, REST, Database, Mail, etc...

Best regards - Claus

On 02.12.2010 23:48, nkrust wrote:
> I was looking more for how the URI should be constructed.
> <from uri="xxxxxxx"/>
> I'm looking to route to different servers based on the VO that will be
> passed from a java class.
>
> Thanks for responding Claude.
>
>


Re: Hor to route using objects

Posted by nkrust <sa...@gmail.com>.
I was looking more for how the URI should be constructed.
<from uri="xxxxxxx"/>
I'm looking to route to different servers based on the VO that will be
passed from a java class.

Thanks for responding Claude.


-- 
View this message in context: http://camel.465427.n5.nabble.com/Hor-to-route-using-objects-tp3290076p3290117.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Hor to route using objects

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 2, 2010 at 11:10 PM, nkrust <sa...@gmail.com> wrote:
>
> Hi,
>
> I'm trying to do a POC on Content Based Routing based on camel.
> From what ever literature that I've seen so far I only see routing happening
> from files, queues etc. But I've not seen any example where I can route
> based on a particular property of a ValueObject.
>
> Is it possible, if so how can it be implemented?

Yeah the Content Based Router can route based on any kind of Object.

in the when clause you just use a predicate which determines the
property on the ValueObject is equal to whatever you specify.
You can implement the predicate using Java code or use some fluent
builder or expression languages.

For example the Camel Simple is an expression language you can use as well

when(simple("${body.xxx} == 'foo)).to("log:foo")
This will invoke the XXX method on the method body and compare if its
equals to foo.
If XXX is a getter you can omit the get.


The Simple language can also be used with Spring XML when defining Camel routes

<when>
   <simple>   ... </simple>
   <to uri="log:foo"/>
</when>

See more here
http://camel.apache.org/simple





> --
> View this message in context: http://camel.465427.n5.nabble.com/Hor-to-route-using-objects-tp3290076p3290076.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



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