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 |
---|
...
Figure 1: Message Dispatcher EIP
Example
...
scenario
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.
Implementing the Example Scenario in WSO2 ESB
Getting Started
The diagram below depicts how to simulate the example scenario using the WSO2 ESB.
...
Figure 1: Message Dispatcher EIP | Figure 2: Message Dispatcher Example Scenario |
---|---|
Sender | Simple Stock Quote Client |
Messages | Simple Stock Quote Requests |
Message Dispatcher | Message Endpoint, Load-Balance Endpoint |
Performers | Simple Stock Quote Server Instances |
Environment
...
setup
...
- Download an 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.
...
- Start three sample Axis2 server instances on ports 9000, 9001 and 9002. For instructions, refer to section ESB Samples Setup - Starting Sample Back-End Services in the WSO2 ESB Documentation.
ESB
...
configuration
3. 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 | ||||
---|---|---|---|---|
|
Code Block | ||||
---|---|---|---|---|
| ||||
<definitions xmlns="http://ws.apache.org/ns/synapse"> <sequence name="fault"> <log level="full"> <property name="MESSAGE" value="Executing default "fault" sequence"/> <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/> <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/> </log> <drop/> </sequence> <sequence name="main"> <in> <send> <endpoint> <loadbalance algorithm="org.apache.synapse.endpoints.algorithms.WeightedRoundRobin"> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService/"/> <property name="loadbalance.weight" value="1"/> </endpoint> <endpoint> <address uri="http://localhost:9001/services/SimpleStockQuoteService/"/> <property name="loadbalance.weight" value="2"/> </endpoint> <endpoint> <address uri="http://localhost:9002/services/SimpleStockQuoteService/"/> <property name="loadbalance.weight" value="3"/> </endpoint> </loadbalance> </endpoint> </send> </in> <out> <send/> </out> </sequence> </definitions> |
Simulating the
...
sample scenario
Repeatedly send several requests to the ESB using the stockquote client as follows
...
language | bash |
---|
:
ant stockquote -Dtrpurl=http://localhost:8280/ -Dsymbol=Foo
Given below is the request sent by the stockquote client in this example.
...
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 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 above.
- endpoint [line 14 in ESB config] - The endpoint element defines the endpoint to which a request should be sent to.
- loadbalance [line 15 in ESB config] - The loadbalance configuration defines a set of endpoints to which incoming requests are distributed to using a particular algorithm. In this example, the algorithm distributes messages in a weighted round robin manner.
...
hidden | true |
---|
...