You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Router <ro...@trash-mail.com> on 2014/11/25 10:58:09 UTC

Passing several POJOs trough multiple routes

Hi,

I converted data from a file into several POJOs which should be available in
different routes for further processing. I tried to store them in the
message header (implements Serializable) but they are just available within
one route. After passing them to the next they are lost. Do I miss something
here? What is the best practice in this case?

Thank you



--
View this message in context: http://camel.465427.n5.nabble.com/Passing-several-POJOs-trough-multiple-routes-tp5759575.html
Sent from the Camel - Users mailing list archive at Nabble.com.

AW: Passing several POJOs trough multiple routes

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Some components don't forward headers. Maybe you are losing header entries on special components.
So instead of searching where you are losing the value, storing as properties, like Claus suggests, seems to be easier.


Jan

> -----Ursprüngliche Nachricht-----
> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Gesendet: Dienstag, 25. November 2014 11:12
> An: users@camel.apache.org
> Betreff: Re: Passing several POJOs trough multiple routes
> 
> Store them as properties on the exchange
> 
> On Tue, Nov 25, 2014 at 10:58 AM, Router <ro...@trash-mail.com> wrote:
> > Hi,
> >
> > I converted data from a file into several POJOs which should be
> > available in different routes for further processing. I tried to
> store
> > them in the message header (implements Serializable) but they are
> just
> > available within one route. After passing them to the next they are
> > lost. Do I miss something here? What is the best practice in this
> case?
> >
> > Thank you
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Passing-several-POJOs-trough-
> multipl
> > e-routes-tp5759575.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
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/


Re: Passing several POJOs trough multiple routes

Posted by Router <ro...@trash-mail.com>.
Cool thanks, this helps!

How would I access this the property via Spring XML? 

Processor:
exchange.setProperty("MyProperty", myObject); // assume method
myObject.getName();

Camel.xml:
<log message="{{MyProperty.name}}"/>

This doesn't work. 



--
View this message in context: http://camel.465427.n5.nabble.com/Passing-several-POJOs-trough-multiple-routes-tp5759575p5759578.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Passing several POJOs trough multiple routes

Posted by Claus Ibsen <cl...@gmail.com>.
Store them as properties on the exchange

On Tue, Nov 25, 2014 at 10:58 AM, Router <ro...@trash-mail.com> wrote:
> Hi,
>
> I converted data from a file into several POJOs which should be available in
> different routes for further processing. I tried to store them in the
> message header (implements Serializable) but they are just available within
> one route. After passing them to the next they are lost. Do I miss something
> here? What is the best practice in this case?
>
> Thank you
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Passing-several-POJOs-trough-multiple-routes-tp5759575.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
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: Passing several POJOs trough multiple routes

Posted by Router <ro...@trash-mail.com>.
Thank you guys for your help! Here's a simple example that works for me:

DataToPOJOProcessor:
exchange.setProperty("MyProperty", myObject); // assume method
myObject.getName();

Camel.xml:
<route id="Myroute1">
	<from uri="MyQueue:incomingData"/>
	<process ref="DataToPOJOProcessor"/>
	<to uri="MyQueue:pojo?transferExchange=true"/>
</route>

<route id="Myroute2">
	<from uri="MyQueue:pojo"/>
	<log message="${property[MyProperty].name}"></log>
	<to uri="mock:test"/>
</route>
 



--
View this message in context: http://camel.465427.n5.nabble.com/Passing-several-POJOs-trough-multiple-routes-tp5759575p5759585.html
Sent from the Camel - Users mailing list archive at Nabble.com.