The following topics are covered under Message Translator EIP.
Introduction to Message Translator
Different Applications typically use different data types. Therefore, for two applications to successfully communicate, we should intermediately translate the messages that pass from one application to the data type compatible with the receiving application. A translator changes the context of a message from one interface to another, allowing message to adhere to message context rules of the back-end service.
The Message Translator EIP is responsible for message translating to ensure compatibility between applications supporting different data types. For more information, refer to http://www.eaipatterns.com/MessageTranslator.html.
Figure 1: Message Translator EIP
Example Scenario for the EIP
The rest of this document explains, through a typical example scenario, how the Content-Based Router EIP can be simulated using the WSO2 ESB.
The example scenario depicts an inventory for stocks and illustrates how the sender sends a request in a particular format that will be transformed into a format which is compatible with the receiver. In the given scenario the sender sends a request which contains the following format,
The format which is expected by the receiver is in the following format,
The scenario explains on how the message can be translated through the WSO2 ESB to a format which is compatible by the receiving application.
Implementing the Example Scenario in WSO2 ESB
The diagram below depicts how to simulate the example scenario using the WSO2 ESB.
Before digging into implementation details, let's take a look at the co-relation of the example scenario and the Message Translator EIP by comparing their core components.
|Figure 1: Message Translator EIP||Figure 2: Message Translator Example Scenario|
|Stock Quote Request|
|The translation is done through the Payload Factory Mediator|
1. Download and install the WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Installation Guide in the WSO2 ESB documentation.
2. Start an instance of Axis2 server. For instructions, refer to section ESB Samples Setup - Starting Sample Back-End Services in the WSO2 ESB Documentation.
3. Start the WSO2 ESB and copy the following configuration to the "Source View" in the management console (Main Menu -> Service Bus -> Source View), using which the example scenario can be explored.
Simulating the Sample Scenario
4. Send a request using a SOAP request client (ex :- SOAP UI) to WSO2 ESB in the following manner,
When the above request was sent to the ESB through the client. the client will be able to notice that the request was successfully generated in the stock quote server.
How the Implementation Works
Let's investigate the elements of the ESB configuration in detail. The line numbers below are mapped with the ESB configuration illustrated in step 3 above.
- main sequence [line 12 in ESB config] - The default sequence which will trigger when the user invokes the ESB server
- in [line 13 in ESB config] - Once the message is hit in the main sequence the message will be diverted into the 'in'
- out [line 33 in ESB config] - Will be triggered after execution of steps defined through the 'in'
- payload factory [line 15 in ESB config] - Will transform the message to the format denoted within the mediator.