How can I add a property during a transformation step

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How can I add a property during a transformation step

Charles Moulliard
Hi,

I would like to know if this is possible to enrich the message(s) (by adding a property or a header) created during a transformation step.

ex :
        from("file:///c:/temp/test?noop=true")
        .unmarshal().csv()
        .to("test-jms:queue:test.queue");

According to this DSL route, the files created in the dir c:/temp/test will be read, parsed and transformed using a CsvDataFormat. Next, the result of this tranformation will be placed into a queue (test.queue).

My question is the following ?

Is it possible to add a property/header to the messages posted in a queue ?

        from("file:///c:/temp/test?noop=true")
        .unmarshal().csv()
        .setProperty("Client", "Jack")
        .to("test-jms:queue:test.queue");

The idea is that in the next route, I can check the property/header name and depending on the value I can process differently the messages.

Regards,

Charles
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: How can I add a property during a transformation step

jstrachan
On 18/03/2008, cmoulliard <[hidden email]> wrote:

>
>  Hi,
>
>  I would like to know if this is possible to enrich the message(s) (by adding
>  a property or a header) created during a transformation step.
>
>  ex :
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .to("test-jms:queue:test.queue");
>
>  According to this DSL route, the files created in the dir c:/temp/test will
>  be read, parsed and transformed using a CsvDataFormat. Next, the result of
>  this tranformation will be placed into a queue (test.queue).
>
>  My question is the following ?
>
>  Is it possible to add a property/header to the messages posted in a queue ?
>
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .setProperty("Client", "Jack")
>         .to("test-jms:queue:test.queue");
>
>  The idea is that in the next route, I can check the property/header name and
>  depending on the value I can process differently the messages.

Absolutely!

We have properties on an Exchange which are intended to be transient
things during the processing, then headers on a Message which are
typically intended to travel over the wire (some endpoints might
filter out or transform some headers).

So if you use

from("file:///c:/temp/test?noop=true")
       .unmarshal().csv()
       .setHeader("Client", "Jack")
       .to("test-jms:queue:test.queue");

it will populate the JMS header "Client"

I guess part of the confusion is the JMS API refers to them as
'properties' :) We've kinda used HTTP/email style terminology for
headers & properties which might cause confusion.

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

Open Source Integration
http://open.iona.com
Reply | Threaded
Open this post in threaded view
|

Re: How can I add a property during a transformation step

Charles Moulliard
The setHeader method does not accept as parameters (string, string) or (string, object) but (string, expression)

The method setHeader(String, Expression) in the type ProcessorType<ProcessorType> is not applicable for the arguments (String, String)

What is purpose of "expression" when we want to place something in the header ?

Regards,

Charles


James.Strachan wrote
On 18/03/2008, cmoulliard <cmoulliard@gmail.com> wrote:
>
>  Hi,
>
>  I would like to know if this is possible to enrich the message(s) (by adding
>  a property or a header) created during a transformation step.
>
>  ex :
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .to("test-jms:queue:test.queue");
>
>  According to this DSL route, the files created in the dir c:/temp/test will
>  be read, parsed and transformed using a CsvDataFormat. Next, the result of
>  this tranformation will be placed into a queue (test.queue).
>
>  My question is the following ?
>
>  Is it possible to add a property/header to the messages posted in a queue ?
>
>         from("file:///c:/temp/test?noop=true")
>         .unmarshal().csv()
>         .setProperty("Client", "Jack")
>         .to("test-jms:queue:test.queue");
>
>  The idea is that in the next route, I can check the property/header name and
>  depending on the value I can process differently the messages.

Absolutely!

We have properties on an Exchange which are intended to be transient
things during the processing, then headers on a Message which are
typically intended to travel over the wire (some endpoints might
filter out or transform some headers).

So if you use

from("file:///c:/temp/test?noop=true")
       .unmarshal().csv()
       .setHeader("Client", "Jack")
       .to("test-jms:queue:test.queue");

it will populate the JMS header "Client"

I guess part of the confusion is the JMS API refers to them as
'properties' :) We've kinda used HTTP/email style terminology for
headers & properties which might cause confusion.

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

Open Source Integration
http://open.iona.com
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: How can I add a property during a transformation step

jstrachan
On 18/03/2008, cmoulliard <[hidden email]> wrote:
>
>  The setHeader method does not accept as parameters (string, string) or
>  (string, object) but (string, expression)

Sorry - try

setHeader("Client").constant("Jack");

You could use something like

setHeader("Client").xpath("/order/customer");

if you need to use expressions etc

I've just added a setHeader(String name, String value) to avoid
further confusion.


>  The method setHeader(String, Expression) in the type
>  ProcessorType<ProcessorType> is not applicable for the arguments (String,
>  String)
>
>  What is purpose of "expression" when we want to place something in the
>  header ?

To support dynamic expressions at runtime - i.e. so based on the
Exchange / Message you get a different value.

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

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