Introduction
This sample demonstrates the functionality of dynamic endpoints. Here you store your endpoints in the registry and refer to them.
Prerequisites
For a list of prerequisites, see Prerequisites to Start the ESB Samples.
Building the sample
The XML configuration for this sample is as follows:
<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> <sequence name="main"> <in> <send> <endpoint key="endpoint/dynamic_endpt_1.xml"/> </send> </in> <out> <send/> </out> </sequence> </definitions>
This configuration file synapse_sample_10.xml
is available in the <ESB_HOME>/repository/samples
directory.
To build the sample
Start the ESB with the sample 10 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.
The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.
Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.
Run the following command to start a second Axis2 server on HTTP port 9001 and HTTPS port 9003.
./axis2server.sh -http 9001 -https 9003
Executing the sample
The sample client used here is the Stock Quote Client, which can operate in several modes. For further details on this sample client and its operation modes, see Stock Quote Client.
To execute the sample client
Run the following command from the
<ESB_HOME>/samples/axis2Client
directory.ant stockquote -Dtrpurl=http://localhost:8280/
- Execute the client immediately again (within 15 seconds of the last execution) using the above command.
- Edit the endpoint definition in
<ESB_HOME>/repository/samples/resources/endpoint/dynamic_endpt_1.xml
by changing the endpoint address tohttp://localhost:9001/services/SimpleStockQuoteService
.
Analyzing the output
When you execute the client for the first time, the message is routed to the SimpleStockQuoteService
on the default Axis2 instance on HTTP port 9000.
When you execute the client immediately again, you will see that the endpoint is cached and reused by the ESB. A similar scenario is explained in Sample 9: Introduction to Dynamic Sequences with the Registry.
When you edit the endpoint definition and execute the client again, you will see that the registry loads the new definition of the endpoint once the cache expires.
Once the registry loads the new definition of the endpoint, you will see that the messages are routed to the second sample Axis2 server on HTTP port 9001.