Set Body
Camel supports the Message Translator from the EIP patterns.
The Message Translator can be done in different ways in Camel:
-
Using template-based Components, with the template being the source for how the message is translated
-
Messages can also be transformed using Data Format to marshal and unmarshal messages in different encodings.
This page is documenting the first approach by using Set Body EIP.
Examples
Using Set Body EIP
You can use a Set Body which uses an Expression to do the transformation:
In the example below we prepend Hello to the message body using the Simple language:
from("direct:cheese")
.setBody(simple("Hello ${body}"))
.to("log:hello");
And in XML DSL:
<route>
<from uri="direct:cheese"/>
<setBody>
<simple>Hello ${body}</simple>
</setBody>
<to uri="log:hello"/>
</route>
What is the difference between Transform and Set Body
The Transform EIP always sets the result on the OUT message body.
Set Body sets the result accordingly to the Exchange Pattern
on the Exchange
.