The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation.
Message Channels
This section explains, through an example scenario, how the Message Channels EIP can be implemented using the WSO2 ESB. The following topics are covered:
Introduction to Message Channels
Message Channels facilitate communication between applications. A sender adds a message to a particular channel. A receiver can then read this message. Channels allow the sender and receiver to synchronize. For more information, go to Message Channel.Â
Figure 1:Â Message Channel EIP
Example scenario
The following diagram depicts an example scenario that is carried out using the ESB. In this example, a stock quote is requested by a client application from a service. As shown below, the client application sends the request to the receiver through a message channel (defined in the ESB). The message channel retrieves the message content from the sender, and it allows the receiver to read the content through the channel.
Figure 2:Â Sample scenario of the Message Channel EIP
Before digging into implementation details, let's look at how the core components in this example scenario map to the Message Channel EIP:
Message Channel EIP (Figure 1) | Message Channel sample Scenario (Figure 2) |
---|---|
Sender Application | Stock Quote Client |
Message System | WSO2 ESB |
Receiver Application | Stock Quote Server |
The ESB configuration
Given below is the ESB configuration for simulating the example scenario explained above.
<definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="message-channel-proxy" startOnLoad="true" transports="http https"> <target> <inSequence> <sequence key="message-channel-sequence" /> </inSequence> <outSequence> <log level="custom"> <property name="sending response to" value="client" /> </log> <respond /> </outSequence> <faultSequence /> </target> </proxy> <sequence name="message-channel-sequence"> <log level="custom"> <property name="sending request to" value="axis2 server" /> </log> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService" /> </endpoint> </send> </sequence> </definitions>
The configuration elements
The elements used in the above ESB configuration are explained below.
- <proxy>Â - This is the proxy service that should be invoked to execute the configuration.
- <inSequence>Â - A message is first received by the proxy service, and then directed to this sequence.
- <outSequence> - This sequence is triggered after the execution of the <inSequence>.
- <sequence> - This is an external sequence, which is invoked by the proxy.
- <send>Â - This is the Send mediator that routes the message to the endpoint indicated by the address URI.
Simulating the example scenario
Now, let's try out the example scenario explained above.
Setting up the environment
You need to set up the ESB, and the back-end service:
- Download theÂ
MessageChannel.zip
 file, which includes the ESB configuration described above. See Setting up the Environment for instructions on setting up the ESB and the back-end service.
When you set up the environment, note that you only need to start one instance of the back-end service (Stock Quote Service) to simulate this example.
Executing the sample
Let's send a request to the ESB using the Stock Quote Client application. Find out more about the Stock Quote Client from the ESB documentation.
- Open a new terminal, and navigate to theÂ
<ESB_HOME>/samples/axis2Client/
 directory. The Stock Quote client application is stored in this directory. Execute the following command to send the request to the ESB.
ant stockquote -Dtrpurl=http://localhost:8280/services/message-channel-proxy
Analyzing the output
When you execute the command above, the ESB first receives the message and then routes it to the back-end service (StockQuoteService). The following output will be printed on the Axis2 server's console:Â
samples.services.SimpleStockQuoteService :: Generating quote for : IBM
The generated stock quote will then be sent to the client application (Stock Quote Client). The following output will be printed on the client application's console:
Standard :: Stock price = $72.42070059233666