Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this scenario, we would use a message translator as a filter for the translation process and we could incorporate multiple translation processes chained together.

Camel has the ability to support the message translator pattern using the processor, bean, or transform possibilities.

Java DSL Processor Example

Code Block
public class 

...

OrderConvertProcessor
                implements Processor {
        public void process(Exchange exchange)
                        throws Exception {
                // do message translation here
        }
}
from("direct:

...

convertOrder")
        .process(new OrderConvertProcessor());

Java DSL Bean Example

Instead of the processor option (shown above), we can also use a POJO bean option. The advantage of using a POJO bean over a processor is that we don’t have to implement any Camel-specific interfaces or types. This type of implementation will allow us to fully decouple your beans from Camel.

Code Block
public class OrderConvertBean {
        public StringconvertOrder(String body) {
                // do message translation here
        }
}
Object transformer = new OrderTransformProcessor());
 OrderConvertBean();
from("direct:convertOrder").bean(transformer);

We can create our bean instance automatically:

Code Block
from("direct:convertOrder")
        .bean(OrderConvertBean.class);

We can identify which method to execute:

Code Block
from("direct:convertOrder")
        .bean(OrderConvertBean.class, "convertOrder");

Java DSL Transform Processor

The Transform option is a specific type of processor that allows us to define a specific response that will be transmitted back to the sender. In the following example, we can see the use of a transform to return a string constant of “Acknowledged” as a response once we have successfully have copied the message to a queue.

Code Block
from("in:tcp://localhost:8888?textline=true")
        .to("jms:queue:order:in")
        .transform(constant("Acknowledged"));