You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Camel Guy <ca...@devguy.com> on 2014/11/11 04:21:54 UTC

Best way to discard changes made to Exchange by invoked route

Hello,

I am using Spring XML. I would like to invoke a route synchronously,
passing the current Exchange. However, I want to discard the changes
that the invoked route makes to the Exchange (e.g., modification of
headers).

So far this is the shortest recipe that results in the desired behavior:

<split><constant>1</constant><to uri="direct:Foo"/></split>

Is there a more elegant way to do this?

I tried <recipientList><constant>direct:Foo</constant></recipientList>
but the current Exchange was modified.


Thanks,
~cg

Re: Best way to discard changes made to Exchange by invoked route

Posted by Camel Guy <ca...@devguy.com>.
Follow up... I discovered that enrich etc. hide property removal but not
property modification. So after switching over to properties, which I think
is better (with the exception that there is no removeProperties in Spring
XML), only split does what I need. ~cg

On Tuesday, November 11, 2014, Camel Guy <ca...@devguy.com> wrote:

> Hi Claus,
>
> Indeed, after running a test program, I confirmed that enrich and
> recipientList 'hide' changes made to properties but not to headers.
> This is not the case, however, for dynamicRouter, which doesn't hide
> changes made to headers or properties.
>
> split works for headers in addition to properties -- I imagine that
> seda does as well.
>
> Is enrich more efficient than split? Wondering if it's worth changing
> the code to use properties.
>
>
> Thanks!
> cg
>
> On Tue, Nov 11, 2014 at 9:30 AM, Claus Ibsen <claus.ibsen@gmail.com
> <javascript:;>> wrote:
> > You can store information as exchange properties and they stick around
> >
> > On Tue, Nov 11, 2014 at 6:00 PM, Camel Guy <camel@devguy.com
> <javascript:;>> wrote:
> >> Hi Claus,
> >>
> >> Thank you again for your reply. Unfortunately I did not see anything
> >> in that FAQ that relates to my problem.
> >>
> >> From route A, I am invoking route B (serially) that deletes a header
> >> key. I would like the header key to exist for route A afterwards even
> >> though route B deleted it. Using a splitter works great. I can not get
> >> enrich or recipientList to work.
> >>
> >> This is a contrived example. The general use case is invoking routes
> >> without side-effects so they can be called recursively -- as
> >> subroutines.
> >>
> >>
> >> Thanks,
> >>
> >> cg
> >>
> >> On Tue, Nov 11, 2014 at 12:00 AM, Claus Ibsen <claus.ibsen@gmail.com
> <javascript:;>> wrote:
> >>> See this FAQ
> >>> http://camel.apache.org/why-is-my-message-body-empty.html
> >>>
> >>> On Tue, Nov 11, 2014 at 8:22 AM, Camel Guy <camel@devguy.com
> <javascript:;>> wrote:
> >>>> Hi Claus,
> >>>>
> >>>> Thanks for the pointer!
> >>>>
> >>>> This program logs "INFO hello" followed by an empty INFO message. I
> >>>> would like the second logged message to also be "INFO hello."
> >>>>
> >>>> Am I doing something wrong?
> >>>>
> >>>> Camel 2.14.0
> >>>>
> >>>>
> >>>> Thank you,
> >>>> ~cg
> >>>>
> >>>> <route>
> >>>>   <from uri="direct:Test"/>
> >>>>   <setHeader headerName='bar'><constant>hello</constant></setHeader>
> >>>>   <log message="${header.bar}"/>
> >>>>   <enrich uri="direct:Foo"/>
> >>>>   <log message="${header.bar}"/>
> >>>> </route>
> >>>>
> >>>> <route>
> >>>>   <from uri="direct:Foo"/>
> >>>>   <removeHeader headerName='bar'/>
> >>>> </route>
> >>>>
> >>>> On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <claus.ibsen@gmail.com
> <javascript:;>> wrote:
> >>>>> See about the content enricher
> >>>>>
> >>>>> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <camel@devguy.com
> <javascript:;>> wrote:
> >>>>>> Hello,
> >>>>>>
> >>>>>> I am using Spring XML. I would like to invoke a route synchronously,
> >>>>>> passing the current Exchange. However, I want to discard the changes
> >>>>>> that the invoked route makes to the Exchange (e.g., modification of
> >>>>>> headers).
> >>>>>>
> >>>>>> So far this is the shortest recipe that results in the desired
> behavior:
> >>>>>>
> >>>>>> <split><constant>1</constant><to uri="direct:Foo"/></split>
> >>>>>>
> >>>>>> Is there a more elegant way to do this?
> >>>>>>
> >>>>>> I tried
> <recipientList><constant>direct:Foo</constant></recipientList>
> >>>>>> but the current Exchange was modified.
> >>>>>>
> >>>>>>
> >>>>>> Thanks,
> >>>>>> ~cg
> >>>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Claus Ibsen
> >>> -----------------
> >>> Red Hat, Inc.
> >>> Email: cibsen@redhat.com <javascript:;>
> >>> Twitter: davsclaus
> >>> Blog: http://davsclaus.com
> >>> Author of Camel in Action: http://www.manning.com/ibsen
> >>> hawtio: http://hawt.io/
> >>> fabric8: http://fabric8.io/
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > Red Hat, Inc.
> > Email: cibsen@redhat.com <javascript:;>
> > 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: Best way to discard changes made to Exchange by invoked route

Posted by Camel Guy <ca...@devguy.com>.
Hi Claus,

Indeed, after running a test program, I confirmed that enrich and
recipientList 'hide' changes made to properties but not to headers.
This is not the case, however, for dynamicRouter, which doesn't hide
changes made to headers or properties.

split works for headers in addition to properties -- I imagine that
seda does as well.

Is enrich more efficient than split? Wondering if it's worth changing
the code to use properties.


Thanks!
cg

On Tue, Nov 11, 2014 at 9:30 AM, Claus Ibsen <cl...@gmail.com> wrote:
> You can store information as exchange properties and they stick around
>
> On Tue, Nov 11, 2014 at 6:00 PM, Camel Guy <ca...@devguy.com> wrote:
>> Hi Claus,
>>
>> Thank you again for your reply. Unfortunately I did not see anything
>> in that FAQ that relates to my problem.
>>
>> From route A, I am invoking route B (serially) that deletes a header
>> key. I would like the header key to exist for route A afterwards even
>> though route B deleted it. Using a splitter works great. I can not get
>> enrich or recipientList to work.
>>
>> This is a contrived example. The general use case is invoking routes
>> without side-effects so they can be called recursively -- as
>> subroutines.
>>
>>
>> Thanks,
>>
>> cg
>>
>> On Tue, Nov 11, 2014 at 12:00 AM, Claus Ibsen <cl...@gmail.com> wrote:
>>> See this FAQ
>>> http://camel.apache.org/why-is-my-message-body-empty.html
>>>
>>> On Tue, Nov 11, 2014 at 8:22 AM, Camel Guy <ca...@devguy.com> wrote:
>>>> Hi Claus,
>>>>
>>>> Thanks for the pointer!
>>>>
>>>> This program logs "INFO hello" followed by an empty INFO message. I
>>>> would like the second logged message to also be "INFO hello."
>>>>
>>>> Am I doing something wrong?
>>>>
>>>> Camel 2.14.0
>>>>
>>>>
>>>> Thank you,
>>>> ~cg
>>>>
>>>> <route>
>>>>   <from uri="direct:Test"/>
>>>>   <setHeader headerName='bar'><constant>hello</constant></setHeader>
>>>>   <log message="${header.bar}"/>
>>>>   <enrich uri="direct:Foo"/>
>>>>   <log message="${header.bar}"/>
>>>> </route>
>>>>
>>>> <route>
>>>>   <from uri="direct:Foo"/>
>>>>   <removeHeader headerName='bar'/>
>>>> </route>
>>>>
>>>> On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>>>> See about the content enricher
>>>>>
>>>>> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
>>>>>> Hello,
>>>>>>
>>>>>> I am using Spring XML. I would like to invoke a route synchronously,
>>>>>> passing the current Exchange. However, I want to discard the changes
>>>>>> that the invoked route makes to the Exchange (e.g., modification of
>>>>>> headers).
>>>>>>
>>>>>> So far this is the shortest recipe that results in the desired behavior:
>>>>>>
>>>>>> <split><constant>1</constant><to uri="direct:Foo"/></split>
>>>>>>
>>>>>> Is there a more elegant way to do this?
>>>>>>
>>>>>> I tried <recipientList><constant>direct:Foo</constant></recipientList>
>>>>>> but the current Exchange was modified.
>>>>>>
>>>>>>
>>>>>> Thanks,
>>>>>> ~cg
>>>>>
>>>
>>>
>>>
>>> --
>>> 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/
>
>
>
> --
> 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: Best way to discard changes made to Exchange by invoked route

Posted by Claus Ibsen <cl...@gmail.com>.
You can store information as exchange properties and they stick around

On Tue, Nov 11, 2014 at 6:00 PM, Camel Guy <ca...@devguy.com> wrote:
> Hi Claus,
>
> Thank you again for your reply. Unfortunately I did not see anything
> in that FAQ that relates to my problem.
>
> From route A, I am invoking route B (serially) that deletes a header
> key. I would like the header key to exist for route A afterwards even
> though route B deleted it. Using a splitter works great. I can not get
> enrich or recipientList to work.
>
> This is a contrived example. The general use case is invoking routes
> without side-effects so they can be called recursively -- as
> subroutines.
>
>
> Thanks,
>
> cg
>
> On Tue, Nov 11, 2014 at 12:00 AM, Claus Ibsen <cl...@gmail.com> wrote:
>> See this FAQ
>> http://camel.apache.org/why-is-my-message-body-empty.html
>>
>> On Tue, Nov 11, 2014 at 8:22 AM, Camel Guy <ca...@devguy.com> wrote:
>>> Hi Claus,
>>>
>>> Thanks for the pointer!
>>>
>>> This program logs "INFO hello" followed by an empty INFO message. I
>>> would like the second logged message to also be "INFO hello."
>>>
>>> Am I doing something wrong?
>>>
>>> Camel 2.14.0
>>>
>>>
>>> Thank you,
>>> ~cg
>>>
>>> <route>
>>>   <from uri="direct:Test"/>
>>>   <setHeader headerName='bar'><constant>hello</constant></setHeader>
>>>   <log message="${header.bar}"/>
>>>   <enrich uri="direct:Foo"/>
>>>   <log message="${header.bar}"/>
>>> </route>
>>>
>>> <route>
>>>   <from uri="direct:Foo"/>
>>>   <removeHeader headerName='bar'/>
>>> </route>
>>>
>>> On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>>> See about the content enricher
>>>>
>>>> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
>>>>> Hello,
>>>>>
>>>>> I am using Spring XML. I would like to invoke a route synchronously,
>>>>> passing the current Exchange. However, I want to discard the changes
>>>>> that the invoked route makes to the Exchange (e.g., modification of
>>>>> headers).
>>>>>
>>>>> So far this is the shortest recipe that results in the desired behavior:
>>>>>
>>>>> <split><constant>1</constant><to uri="direct:Foo"/></split>
>>>>>
>>>>> Is there a more elegant way to do this?
>>>>>
>>>>> I tried <recipientList><constant>direct:Foo</constant></recipientList>
>>>>> but the current Exchange was modified.
>>>>>
>>>>>
>>>>> Thanks,
>>>>> ~cg
>>>>
>>
>>
>>
>> --
>> 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/



-- 
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: Best way to discard changes made to Exchange by invoked route

Posted by Camel Guy <ca...@devguy.com>.
Hi Claus,

Thank you again for your reply. Unfortunately I did not see anything
in that FAQ that relates to my problem.

>From route A, I am invoking route B (serially) that deletes a header
key. I would like the header key to exist for route A afterwards even
though route B deleted it. Using a splitter works great. I can not get
enrich or recipientList to work.

This is a contrived example. The general use case is invoking routes
without side-effects so they can be called recursively -- as
subroutines.


Thanks,

cg

On Tue, Nov 11, 2014 at 12:00 AM, Claus Ibsen <cl...@gmail.com> wrote:
> See this FAQ
> http://camel.apache.org/why-is-my-message-body-empty.html
>
> On Tue, Nov 11, 2014 at 8:22 AM, Camel Guy <ca...@devguy.com> wrote:
>> Hi Claus,
>>
>> Thanks for the pointer!
>>
>> This program logs "INFO hello" followed by an empty INFO message. I
>> would like the second logged message to also be "INFO hello."
>>
>> Am I doing something wrong?
>>
>> Camel 2.14.0
>>
>>
>> Thank you,
>> ~cg
>>
>> <route>
>>   <from uri="direct:Test"/>
>>   <setHeader headerName='bar'><constant>hello</constant></setHeader>
>>   <log message="${header.bar}"/>
>>   <enrich uri="direct:Foo"/>
>>   <log message="${header.bar}"/>
>> </route>
>>
>> <route>
>>   <from uri="direct:Foo"/>
>>   <removeHeader headerName='bar'/>
>> </route>
>>
>> On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <cl...@gmail.com> wrote:
>>> See about the content enricher
>>>
>>> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
>>>> Hello,
>>>>
>>>> I am using Spring XML. I would like to invoke a route synchronously,
>>>> passing the current Exchange. However, I want to discard the changes
>>>> that the invoked route makes to the Exchange (e.g., modification of
>>>> headers).
>>>>
>>>> So far this is the shortest recipe that results in the desired behavior:
>>>>
>>>> <split><constant>1</constant><to uri="direct:Foo"/></split>
>>>>
>>>> Is there a more elegant way to do this?
>>>>
>>>> I tried <recipientList><constant>direct:Foo</constant></recipientList>
>>>> but the current Exchange was modified.
>>>>
>>>>
>>>> Thanks,
>>>> ~cg
>>>
>
>
>
> --
> 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: Best way to discard changes made to Exchange by invoked route

Posted by Claus Ibsen <cl...@gmail.com>.
See this FAQ
http://camel.apache.org/why-is-my-message-body-empty.html

On Tue, Nov 11, 2014 at 8:22 AM, Camel Guy <ca...@devguy.com> wrote:
> Hi Claus,
>
> Thanks for the pointer!
>
> This program logs "INFO hello" followed by an empty INFO message. I
> would like the second logged message to also be "INFO hello."
>
> Am I doing something wrong?
>
> Camel 2.14.0
>
>
> Thank you,
> ~cg
>
> <route>
>   <from uri="direct:Test"/>
>   <setHeader headerName='bar'><constant>hello</constant></setHeader>
>   <log message="${header.bar}"/>
>   <enrich uri="direct:Foo"/>
>   <log message="${header.bar}"/>
> </route>
>
> <route>
>   <from uri="direct:Foo"/>
>   <removeHeader headerName='bar'/>
> </route>
>
> On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <cl...@gmail.com> wrote:
>> See about the content enricher
>>
>> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
>>> Hello,
>>>
>>> I am using Spring XML. I would like to invoke a route synchronously,
>>> passing the current Exchange. However, I want to discard the changes
>>> that the invoked route makes to the Exchange (e.g., modification of
>>> headers).
>>>
>>> So far this is the shortest recipe that results in the desired behavior:
>>>
>>> <split><constant>1</constant><to uri="direct:Foo"/></split>
>>>
>>> Is there a more elegant way to do this?
>>>
>>> I tried <recipientList><constant>direct:Foo</constant></recipientList>
>>> but the current Exchange was modified.
>>>
>>>
>>> Thanks,
>>> ~cg
>>



-- 
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: Best way to discard changes made to Exchange by invoked route

Posted by Camel Guy <ca...@devguy.com>.
Hi Claus,

Thanks for the pointer!

This program logs "INFO hello" followed by an empty INFO message. I
would like the second logged message to also be "INFO hello."

Am I doing something wrong?

Camel 2.14.0


Thank you,
~cg

<route>
  <from uri="direct:Test"/>
  <setHeader headerName='bar'><constant>hello</constant></setHeader>
  <log message="${header.bar}"/>
  <enrich uri="direct:Foo"/>
  <log message="${header.bar}"/>
</route>

<route>
  <from uri="direct:Foo"/>
  <removeHeader headerName='bar'/>
</route>

On Mon, Nov 10, 2014 at 10:06 PM, Claus Ibsen <cl...@gmail.com> wrote:
> See about the content enricher
>
> On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
>> Hello,
>>
>> I am using Spring XML. I would like to invoke a route synchronously,
>> passing the current Exchange. However, I want to discard the changes
>> that the invoked route makes to the Exchange (e.g., modification of
>> headers).
>>
>> So far this is the shortest recipe that results in the desired behavior:
>>
>> <split><constant>1</constant><to uri="direct:Foo"/></split>
>>
>> Is there a more elegant way to do this?
>>
>> I tried <recipientList><constant>direct:Foo</constant></recipientList>
>> but the current Exchange was modified.
>>
>>
>> Thanks,
>> ~cg
>

Re: Best way to discard changes made to Exchange by invoked route

Posted by Claus Ibsen <cl...@gmail.com>.
See about the content enricher

On Tue, Nov 11, 2014 at 4:21 AM, Camel Guy <ca...@devguy.com> wrote:
> Hello,
>
> I am using Spring XML. I would like to invoke a route synchronously,
> passing the current Exchange. However, I want to discard the changes
> that the invoked route makes to the Exchange (e.g., modification of
> headers).
>
> So far this is the shortest recipe that results in the desired behavior:
>
> <split><constant>1</constant><to uri="direct:Foo"/></split>
>
> Is there a more elegant way to do this?
>
> I tried <recipientList><constant>direct:Foo</constant></recipientList>
> but the current Exchange was modified.
>
>
> Thanks,
> ~cg



-- 
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/