Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Table of Contents

...

The Message Dispatcher EIP consumes messages from a single channel , and distributes them among several other performers. It allows multiple consumers on a single channel to coordinate their message processing. For more information, refer to http://www.eaipatterns.com/MessageDispatcher.html.

...

This example scenario demonstrates how to distribute messages among several performers using the WSO2 weighted load balance mediator. We have several Axis2 server instances, each considered to be a performer.

...

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

Figure 1: Message Dispatcher EIP Figure 2: (Figure 1)Message Dispatcher Example Scenario (Figure 2)
SenderSimple Stock Quote Client 
MessagesSimple Stock Quote Requests
Message DispatcherMessage Endpoint, Load-Balance Endpoint
PerformersSimple Stock Quote Server Instances

Environment setup

  1. Download an 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 Getting Started in the WSO2 ESB documentation.
  2. Start three sample Axis2 server instances on ports 9000, 9001, and 9002. For instructions, refer to the section ESB Samples Setup - Starting Sample Back-End Services in the WSO2 ESB Documentationdocumentation.

ESB configuration

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

Anchor
step3
step3

...

Simulating the sample scenario

Repeatedly send several requests to the ESB using the

...

Stock Quote client as follows:

ant stockquote -Dtrpurl=http://localhost:8280/ -Dsymbol=Foo

Given below Following is the request sent by the stockquote Stock Quote client in this example.:

Code Block
languagehtml/xml
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
   <soapenv:Header />
   <soapenv:Body>
        <ser:getQuote>        
         <ser:request>
             <ser:symbol>Foo</ser:symbol>
         </ser:request>      
      </ser:getQuote>
   </soapenv:Body>
</soapenv:Envelope>

Note in each Axis2 server console that the requests are distributed among several servers in a weighted manner. Servers running on port 9000, 9001, and 9002 receives receive the request in that order until the process starts over again in a round-robin manner.

How the implementation works

Let's investigate the elements of the ESB configuration in detail. The line numbers below refer to the ESB configuration in step 3 shown above.

  • endpoint [line 14 in ESB config] - The Defines the endpoint element defines the endpoint to which a where the request should be sent to
  • loadbalance [line 15 in ESB config] - The loadbalance configuration defines Defines a set of endpoints to which where incoming requests are distributed to using a particular algorithm. In this example, the algorithm distributes messages in a weighted round-robin manner.