Message Translator

Camel supports the Message Translator from the EIP patterns.

image

The Message Translator can be done in different ways in Camel:

  • Using Transform or Set Body in the DSL

  • Calling a Processor or bean to perform the transformation

  • 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:

from("direct:cheese")
    .setBody(simple("Hello ${body}"))
    .to("log:hello");

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:

from("activemq:cheese")
  .bean("myTransformerBean", "doTransform")
  .to("activemq:wine");

Message Translator with Processor

You can also use a Processor to do the transformation:

from("activemq:cheese")
  .process(new MyTransformerProcessor())
  .to("activemq:wine");

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.

from("activemq:cheese")
    .to("velocity:com/acme/MyResponse.vm")
    .to("activemq:wine");

Message Translator using Data Format

See Marshal EIP for more details and examples.