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.

Invalid Message Channel

This section explains, through an example scenario, how the Invalid Message Channel EIP can be implemented using WSO2 ESB. The following topics are covered:

Introduction to Invalid Message Channel

The Invalid Message Channel EIP pattern allows administrators to define an error indication that appears when an endpoint fails to process a request. For more information, refer to http://www.eaipatterns.com/InvalidMessageChannel.html.

 

 

 

 

 

Figure 1: Invalid Message Channel EIP

Example scenario

The example scenario creates a deliberate error situation to demonstrate how the ESB handles errors on message failures. It requires a live Axis2 server instance to successfully provide a response to the sender, and the server instance will be shut down before sending a request. You will observe how the ESB directs the process to the faultsequence mediator, which indicates the message invalidity to the user.

The diagram below depicts how to simulate the example scenario using the WSO2 ESB.

Figure 2: Example Scenario of the Invalid Message Channel EIP

Before digging into implementation details, let's take a look at the relationship between the example scenario and the Invalid Message Channel EIP by comparing their core components.

Invalid Message Channel EIP (Figure 1)
Invalid Message Channel Example Scenario (Figure 2)
SenderStock Quote Client
ChannelTarget Endpoint
ReceiverStock Quote Service Instance
Invalid Message ChannelFaultSequence

Environment setup

  1. Download and install 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 the sample Axis2 server. For instructions, refer to the section Starting the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.

ESB configuration

Start the ESB server and log into its management console UI (https://localhost:9443/carbon). In the management console, navigate to the Main menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.

<!-- Invalid Message Chanel Proxy-->
<definitions xmlns="http://ws.apache.org/ns/synapse">
   <proxy name="InvalidMessageChannelProxy">
        <target>
   		 <endpoint> 
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> 
        </endpoint> 
        <inSequence>
              <log level="full" />         
        </inSequence>
        <outSequence>
                <log level="full" />
        </outSequence>
     <faultSequence>
          <log level="full"> 
                    <property name="MESSAGE" value="Failure Message..."/> 
                    <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/> 
                    <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/> 
              </log>
         <drop />
       </faultSequence>
        </target> 
    <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions>

When the server receives a request and the endpoint referred through the ESB is unavailable, the server triggers an error message. The ESB diverts the response to the invalid message channel. 

Simulating the sample scenario

  1. Pass the following message to the WSO2 ESB. You can use SoapUI or WSO2 ESB's Try It tool. To invoke the Try It tool, log into the ESB management console, navigate to the Services menu under the Main menu and select the List sub menu. Then select InvalidMessageChannelProxy and pass the following request to the ESB. 

    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
       <soap:Header/>
       <soap:Body>
          <ser:getQuote>
             <!--Optional:-->
             <ser:request>
                <!--Optional:-->
                <xsd:symbol>foo</xsd:symbol>
             </ser:request>
          </ser:getQuote>
       </soap:Body>
    </soap:Envelope>

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 shown above.

  • Proxy Service [line 3 of ESB config] - Defines the proxy service InvalidMessageChannelProxy with a target endpoint to the back end service. 
  • faultSequence [line 14 of ESB config] - Defines a fault sequence to execute in the event of a fault. It acts as the Invalid Message Channel for this EIP. In this example configuration, we log the fault as an error, but you can place any of the usual mediators inside this sequence. For example, you could pass the invalid message to another service or back to the client. Â