...
icon | false |
---|
This
...
This section explains, through an example scenario, how the Dynamic Router EIP can be implemented using WSO2 ESB. The following topics are covered:
Table of Contents | ||
---|---|---|
|
...
The diagram below depicts how to simulate the example scenario using WSO2 ESB.
Figure 2: Dynamic Router Example Scenario
Before digging into implementation details, let's take a look at the relationship between the example scenario and the Dynamic Router EIP by comparing their core components.
...
Code Block | ||
---|---|---|
| ||
<definitions xmlns="http://ws.apache.org/ns/synapse"> <registry<localEntry providerkey="org.wso2.carbon.mediation.registry.WSO2RegistryConfigA"> <value>foo</value> <parameter name="cachableDuration">15000</parameter> <<description/registry>> <taskManager provider="org.wso2.carbon.mediation.ntask.NTaskTaskManager"/></localEntry> <localEntry key="ConfigAConfigC"> <value>foo<<value>WSO2</value> <description/> </localEntry> <localEntry key="ConfigCConfigB"> <value>WSO2<<value>bar</value> <description/> </localEntry> <proxy xmlns="http://ws.apache.org/ns/synapse" name="DynamicRouterProxy" startOnLoad="true" <localEntry key="ConfigB">statistics="disable" trace="disable" transports="http,https"> <target> <inSequence> <value>bar</value> <log level="full"/> <description/<switch source="get-property('To')"> </localEntry> <sequence<case nameregex="SendServiceAhttp://localhost:9000.*"> <filter xmlns:m0="http://services.samples" xpath="get-property('ConfigA') = //m0:getQuote/m0:request/m0:symbol/text()"> <then> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> </then> <else> <log level="custom"> <property name="MESSAGE" value="TheRegistry back-end service does not support the requested symbol.Value Doesn't Matched"/> </log> </else> </filter> </sequence>case> <sequence<case nameregex="SendServiceBhttp://localhost:9001.*"> <filter xmlns:m0="http://services.samples" xpath="get-property('ConfigB') = //m0:getQuote/m0:request/m0:symbol/text()"> <then> <send> <endpoint> <address uri="http://localhost:9001/services/SimpleStockQuoteService"/> </endpoint> </send> </then> <else> <log level="custom"> <property name="MESSAGE" value="TheRegistry back-end service does not support the requested symbol.Value Doesn't Matched"/> </log> </else> </filter> </sequence>case> <sequence name="SendServiceC"> <case regex="http://localhost:9002.*"> <filter xmlns:m0="http://services.samples" xpath="get-property('ConfigC') = //m0:getQuote/m0:request/m0:symbol/text()"> <then> <send> <endpoint> <address uri="http://localhost:9002/services/SimpleStockQuoteService"/> </endpoint> </send> </then> <else> <log level="custom"> <property name="MESSAGE" value="TheRegistry back-end service does not support the requested symbol."/> Value Doesn't Matched"/> </log> </else> </filter> </sequence> <sequence name="main"> <in> <log level="full"/> <switch source="get-property('To')"> <case regex="http://localhost:9000.*"> <sequence key="SendServiceA"/> </case> <case regex="http://localhost:9001.*"> <sequence key="SendServiceB"/> </case> <case regex="http://localhost:9002.*"> <sequence key="SendServiceC"/> </case> </switch> </in>inSequence> <outSequence> <out> <send/> </out> outSequence> </sequence> <sequence name="fault"> <!-- Log the message at the full log level with the ERROR_MESSAGE and the ERROR_CODE--> <log level="full"> <property name="MESSAGE" value="Executing default 'fault' sequence"/> <property expression="get-property('ERROR_CODE')" name="ERROR_CODE"/> <property expression="get-property('ERROR_MESSAGE')" name="ERROR_MESSAGE"/> </log> <!-- Drops the messages by default if there is a fault --> <drop/> </sequence> <!-- You can add any flat sequences, endpoints, etc.. to this synapse.xml file if you do *not* want to keep the artifacts in several files --> target> <description/> </proxy> </definitions> |
The above configuration helps you explore the sample scenario.
...
Code Block | ||
---|---|---|
| ||
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/services/DynamicRouterProxy -Dsymbol=foo
ant stockquote -Daddurl=http://localhost:9001/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=bar
ant stockquote -Daddurl=http://localhost:9002/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=WSO2
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=bar
ant stockquote -Daddurl=http://localhost:9001/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=WSO2
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=foo |
You will see that only the first three commands are sent to the back-end services. This is because the symbols passed within those requests are the symbols associated with the particular endpoint service.
You need to send the corresponding port correctly with the symbol to get the response as follows:
- ant stockquote -Dtrpurl=http://localhost:8280/services/DynamicRouterProxy -Dsymbol=foo -Daddurl=http://localhost:9000/services/SimpleStockQuoteService
- ant stockquote -Dtrpurl=http://localhost:8280/services/DynamicRouterProxy -Dsymbol=bar -Daddurl=http://localhost:9001/services/SimpleStockQuoteService
- ant stockquote -Dtrpurl=http://localhost:8280/services/DynamicRouterProxy -Dsymbol=WSO2 -Daddurl=http://localhost:9002/services/SimpleStockQuoteService
If you send a different request you view the follwoing message in the ESB Console:
[EI-Core] INFO - LogMediator MESSAGE = Registry Value Doesn't Matched
How the implementation works
...