...
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) |
---|---|
Sender | StockQuoteClient |
Recipient List | RecipientList mediator |
Receivers (A, B, C, D) | SimpleStockQuote Service Instances (foo, WSO2) |
Environment setup
- 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 Getting Started Installation Guide in the WSO2 ESB documentation.
- Deploy the
SimpleStockQuoteService
and start three instances of Axis2 Server in ports 9000, 9001, 9002, and 9003. For instructions, refer to the section Setting up the ESB Samples Setup - Starting Sample Back-End Servicesthe 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
ESB configuration
Start the ESB server and log into its management console UI (https:
//localhost:9443/carbon
). In the management console, navigate navigate to the Main Menu, click Service Bus and then Source View 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. Anchor step3 step3
Code Block | ||||
---|---|---|---|---|
| ||||
<!-- Would Route the Message Based on the List of Recipients--> <definitions xmlns="http://ws.apache.org/ns/synapse"> <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry"> <parameter name="root">file:repository/samples/resources/</parameter> <parameter name="cachableDuration">15000</parameter> </registry> <proxy name="RecipientListProxy"> <target> <inSequence> <switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples"> <!-- First the recipient list will be identified --> <case regex="Foofoo"> <send> <!--Dynamic Recipient List--> <endpoint> <recipientlist> <endpoint xmlns="http://ws.apache.org/ns/synapse"> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> <endpoint xmlns="http://ws.apache.org/ns/synapse"> <address uri="http://localhost:9001/services/SimpleStockQuoteService"/> </endpoint> </recipientlist> </endpoint> </send> <drop/> </case> <case regex="WSO2"> <send> <!--Dynamic Recipient List--> <endpoint> <recipientlist> <endpoint xmlns="http://ws.apache.org/ns/synapse"> <address uri="http://localhost:9002/services/SimpleStockQuoteService"/> </endpoint> <endpoint xmlns="http://ws.apache.org/ns/synapse"> <address uri="http://localhost:9003/services/SimpleStockQuoteService"/> </endpoint> </recipientlist> </endpoint> </send> <drop/> </case> <default> <!-- Message Should Be Discarded --> </default> </switch> </inSequence> <outSequence> <send/> </outSequence> </target> </proxy> </definitions> |
...
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.
...
Note that the ESB sends the request to servers running on ports 9002 and 9003. If you change the symbol to Foofoo, 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
Server ouput:
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
...