blob: a46ac8629534bae5bca857e03751b52238166fd1 [file] [log] [blame]
[[messageTranslator-eip]]
= Message Translator
Camel supports the
http://www.enterpriseintegrationpatterns.com/MessageTranslator.html[Message
Translator] from the xref:enterprise-integration-patterns.adoc[EIP
patterns] by using an arbitrary xref:processor.adoc[Processor] in the
routing logic, by using a xref:bean-integration.adoc[bean] to perform
the transformation, or by using transform() in the DSL. You can also use
a xref:data-format.adoc[Data Format] to marshal and unmarshal messages
in different encodings.
image::eip/MessageTranslator.gif[image]
== Samples
You can transform a message using Camel's
xref:bean-integration.adoc[Bean Integration] to call any method on a
bean in your xref:registry.adoc[Registry] such as your
xref:spring.adoc[Spring] XML configuration file as follows
[source,java]
----
from("activemq:SomeQueue")
.bean("myTransformerBean", "myMethodName")
.to("mqseries:AnotherQueue");
----
Where the "myTransformerBean" would be defined in a Spring XML file or
defined in JNDI etc. You can omit the method name parameter from
beanRef() and the xref:bean-integration.adoc[Bean Integration] will try
to deduce the method to invoke from the message exchange.
or you can add your own explicit xref:processor.adoc[Processor] to do
the transformation
or you can use the DSL to explicitly configure the transformation
You can also use xref:spring-xml-extensions.adoc[Spring XML Extensions]
to do a transformation. Basically any xref:expression.adoc[Expression]
language can be substituted inside the transform element as shown below
Or you can use the xref:bean-integration.adoc[Bean Integration] to
invoke a bean
[source,xml]
----
<route>
<from uri="activemq:SomeQueue"/>
<bean ref="myTransformerBean" method="myMethodName"/>
<to uri="mqseries:AnotherQueue"/>
</route>
----
You can also use xref:templating.adoc[Templating] to consume a message
from one destination, transform it with something like
xref:components::velocity-component.adoc[Velocity] or xref:components::xquery-component.adoc[XQuery] and then send
it on to another destination. For example using InOnly (one way
messaging)
[source,java]
----
from("activemq:My.Queue")
.to("velocity:com/acme/MyResponse.vm")
.to("activemq:Another.Queue");
----
If you want to use InOut (request-reply) semantics to process requests
on the *My.Queue* queue on xref:components::activemq-component.adoc[ActiveMQ] with a template
generated response, then sending responses back to the JMSReplyTo
Destination you could use this.
[source,java]
----
from("activemq:My.Queue")
.to("velocity:com/acme/MyResponse.vm");
----