Message Translator
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.
Example
Each of the approaches above is documented in the following examples:
Message Translator with Transform EIP
You can use a Transform which uses an Expression to do the transformation:
In the example below, we prepend Hello to the message body using the Simple language:
-
Java
-
XML
from("direct:cheese")
.setBody(simple("Hello ${body}"))
.to("log:hello");
<route>
<from uri="activemq:cheese"/>
<transform>
<simple>Hello ${body}</simple>
</transform>
<to uri="activemq:wine"/>
</route>
Message Translator with Bean
You can transform a message using Camel’s Bean Integration to call any method on a bean that performs the message translation:
-
Java
-
XML
from("activemq:cheese")
.bean("myTransformerBean", "doTransform")
.to("activemq:wine");
<route>
<from uri="activemq:cheese"/>
<bean ref="myTransformerBean" method="doTransform"/>
<to uri="activemq:wine"/>
</route>
Message Translator with Processor
You can also use a Processor to do the transformation:
-
Java
-
XML
from("activemq:cheese")
.process(new MyTransformerProcessor())
.to("activemq:wine");
<route>
<from uri="activemq:cheese"/>
<process ref="myTransformerProcessor"/>
<to uri="activemq:wine"/>
</route>
Message Translator using Templating Components
You can also consume a message from one destination, transform it with something like Velocity or XQuery, and then send it on to another destination.
-
Java
-
XML
from("activemq:cheese")
.to("velocity:com/acme/MyResponse.vm")
.to("activemq:wine");
<route>
<from uri="activemq:cheese"/>
<to uri="velocity:com/acme/MyResponse.vm"/>
<to uri="activemq:wine"/>
</route>
Message Translator using Data Format
See Marshal EIP for more details and examples.