This section explains, through an example scenario, how the Recipient List EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Recipient List
The Recipient List EIP routes a message to a list of dynamically specified recipients. It processes an incoming message and identifies its list of recipients. Once the list is identified, the message will be sent to all recipient channels. For more information, refer to http://www.eaipatterns.com/RecipientList.html.
Figure 1: Recipient List EIP
This example scenario is a stock quote service sending a stock quote request to recipients that are instances of a sample Axis2 server. The Switch mediator identifies the content of the client request and distributes the content among the Recipient List endpoints.
The diagram below depicts how to simulate the example scenario using the WSO2 ESB.
Figure 2: Recipient List Example Scenario
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Recipient List EIP by comparing their core components.
|Recipient List EIP (Figure 1)||Recipient List Example Scenario (Figure 2)|
|Recipient List||RecipientList mediator|
|Receivers (A, B, C, D)||SimpleStockQuote Service Instances (foo, WSO2)|
- 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.
- Deploy the
SimpleStockQuoteServiceand start three instances of Axis2 Server in ports 9000, 9001, 9002, and 9003. For instructions, refer to the section Setting up the ESB Samples - Starting the Axis2 server in the WSO2 ESB documentation.
- You need four Axis2 servers as follows:
-http 9000 -https 9004 -name MyServer1
-http 9001 -https 9005 -name MyServer2
-http 9002 -https 9006 -name MyServer3
-http 9003 -https 9007 -name MyServer4
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
Send a request using the Stock Quote client to WSO2 ESB in the following manner. For information about the Stock Quote client, refer to the Sample Clients section in the WSO2 ESB documentation.
ant stockquote -Dtrpurl=http://localhost:8280/services/RecipientListProxy -Dsymbol=WSO2
Note that the ESB sends the request to servers running on ports 9002 and 9003. If you change the symbol to foo, it will send the requests to servers running on port 9000 and 9001
- When you send the following command with -Dsymbol=WSO2: ant stockquote -Dtrpurl=http://localhost:8280/services/RecipientListProxy -Dsymbol=WSO2
you see the following output in Axis2 9002 and 9003 servers:
Standard :: Stock price = $97.2597329576317
samples.services.SimpleStockQuoteService :: Generating quote for : WSO2
- When you send the following command -Dsymbol=foo: ant stockquote -Dtrpurl=http://localhost:8280/services/RecipientListProxy -Dsymbol=WSO2
you see the following output in Axis2 9000 and 9001 servers:
Standard :: Stock price = $65.69553059675577
Server ouput: samples.services.SimpleStockQuoteService :: Generating quote for : foo
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.
- Switch [line 10 in ESB config] - The Switch mediator performs a switch/case based on the symbol found inside the original request. In this example scenario, one of two are used, based on the value of the mediators
symbolelement in the request.
- recipientList [line 16 in ESB config] - the
recipientListmediator lists several endpoints inside the
sendtags. ESB will forward the request to all endpoints in this list.