This section explains, through an example scenario, how the Messaging Gateway EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Messaging Gateway
The Messaging Gateway EIP encapsulates message-specific code from the rest of the application. It is a class that wraps messaging-specific method calls and exposes domain-specific methods to the application. Only the Messaging Gateway knows about the actual implementation of the messaging system. The rest of the application calls the methods of the Messaging Gateway, which are exposed to external applications. For more information, refer to http://www.eaipatterns.com/MessagingGateway.html.
Figure 1: Messaging Gateway EIP
This example scenario demonstrates creating a proxy service with a
publishWSDL element. The published WSDL's methods act as the Message Gateway, hiding details of the actual back-end service, and exposing only domain-specific methods to the client application.
Proxy services in WSO2 ESB act as Messaging Gateways, abstracting the details of the actual back-end services from implementing clients. For a more complex example of how WSO2 ESB can act as a Messaging Gateway, refer to Health Care Scenario, where a single Proxy Service acts as a Messaging Gateway between several back-end services.
The diagram below depicts how to simulate the example scenario using WSO2 ESB.
Figure 2: Example Scenario of the Messaging Gateway EIP
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Messaging Gateway EIP by comparing their core components.
|Messaging Gateway EIP (Figure 1)||Messaging Gateway Example Scenario (Figure 2)|
|Application||Simple Stock Quote Client / Service|
|Messaging Gateway||Proxy Service|
- 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.
- Start the sample Axis2 server. For instructions, refer to the section Setting Up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.
- Copy the sample_proxy_3.wsdl file into your
Start the ESB server and log into its management console UI (
//). 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.
Simulating the sample scenario
If you navigate to
http://localhost:9000/services/SimpleStockQuoteService, you can see the WSDL file of the back-end server. There are five methods exposed externally, but the Proxy Service
SimpleQuoteProxy exposes only four externally, filtering out the
getFullQuote method. See the
SimpleQuoteProxy WSDL file in
Send the following request using a SOAP client like SoapUI to the
After sending the above message to the server, you'll get a server error as 'The endpoint reference (EPR) for the Operation not found is /services/StockQuoteProxy and the WSA Action = urn:getFullQuote. The reason for this error is that the
getFullQuote method is not exposed to
SimpleQuoteProxy, although the back-end server supports it.
Now, specify a different published WSDL file as follows and send the same SOAP message to the server again.
Note that you get the correct response from the server, since the new WSDL of the proxy service is the same as the back-end service.
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 [line 2 in ESB config] - Defines a new proxy service called
- endpoint [line 4 in ESB config] - Defines the endpoint of the actual back-end service that this proxy service is connected to.
- publishWSDL [line 11 in ESB config] - Defines the WSDL file to expose for this proxy service. If no
publishWSDLis given, the actual back-end service's WSDL is exposed.