Objective: Introduction to Dynamic Sequences with a Registry.
<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 key="sequence/dynamic_seq_1.xml"/> </definitions>
Prerequisites
- Start the Synapse configuration numbered 9:
wso2esb-samples -sn 9
. - Start the Axis2 server and deploy the
SimpleStockQuoteService
if not already done.
This example introduces the dynamic behavior of ESB through the use of a Registry. ESB supports dynamic definitions for sequences and endpoints and, as seen before, for resources. In this example, we define a Synapse configuration which references a sequence definition specified as a registry key. The registry key resolves to the actual content of the sequence which would be loaded dynamically by ESB at runtime and cached appropriately as per its definition in the registry. Once the cache expires, ESB would recheck the meta information for the definition, reload the sequence definition if necessary, and recache it again.
Once ESB is started, execute the stock quote client as ant stockquote...
You will notice that that ESB fetches the definition of the sequence from the registry and executes its rules as follows.
ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator <dynamic_sequence> :: mediate() ... [HttpServerWorker-1] INFO LogMediator - message = *** Test Message 1 ***
Now if you execute the client immediately (within 15 seconds of the last execution), you will notice that the sequence was not reloaded. If you edit the sequence definition in repository/samples/resources/sequence/dynamic_seq_1.xml
(edit the log message to read as "Test Message 2") and execute the client again, you will notice that the new message is not yet visible (if you execute this within 15 seconds of loading the resource for the first time) However, after 15 seconds elapsed since the original caching of the sequence, you will notice that the new sequence is loaded and executed by ESB from the following log messages.
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator <dynamic_sequence> :: mediate() ... [HttpServerWorker-1] INFO LogMediator - message = *** Test Message 2 ***
The cache timeout could be tuned appropriately by configuring the URL registry to suite the environment and the needs.