Normalizer
In some data integration scenarios, it can be common for us to receive multiple inbound messages from different business partners or from different application systems. When that happens, these messages may have the same meaning, but follow different formats, depending on the external systems, their data content, and different preferences. The Normalizer data integration pattern is used to process messages that are semantically equivalent but can arrive in different formats.
Â
Â
The Normalizer pattern will utilize a Message Router to route the incoming message to the appropriate Message Translator. This implementation will require that the Message Router be able to detect the type of the inbound message. Many messaging applications will equip each message with a type indicator field in the Message Header to simplify this task.
In the above illustration, we can see that we have implemented the Normalizer pattern using a Content-Based Router in conjunction with several Message Translators.
Â
Normalizer using XML DSL
In this example, we are converting two different XML messages into a common format and then the commonly formatted messages are routed.
Â
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:input"/>
<choice>
<when>
<xpath>/partner</xpath>
<to uri="bean:normalizer?method=convertPartner"/>
</when>
<when>
<xpath>/customer</xpath>
<to uri="bean:normalizer?method=convertCustomer"/>
</when>
</choice>
<to uri="out:result"/>
</route>
</camelContext>
<bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/>
Â
Using Java Bean as the Normalizer:
Â
public class MyNormalizer {
public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) {
exchange.getMessage().setBody(createPerson(name));
}
public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) {
exchange.getMessage().setBody(createPerson(name));
}
private String createPerson(String name) {
return "<person name=\" + name + \"/>";
}
}
Â