Sample 9: Introduction to Dynamic Sequences with Registry

<definitions xmlns="http://ws.apache.org/ns/synapse"> <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"> <parameter name="root">file:./repository/conf/sample/resources/</parameter> <parameter name="cachableDuration">15000</parameter> </registry> <sequence name="main"> <sequence key="sequence/dynamic_seq_1.xml"/> </sequence> </definitions>

Objective

Demonstrating the ability to load sequence definitions dynamically from the remote registry.

Pre-requisites

  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Start Synapse using the configuration numbered 9 (repository/conf/sample/synapse_sample_9.xml)
    Unix/Linux: sh synapse.sh -sample 9
    Windows: synapse.bat -sample 9

Executing the Client

This example demonstrates the dynamic behaviour of Synapse through the use of a registry. Synapse supports dynamic definitions for sequences and endpoints, and as seen before, for configuration resources (eg: schema files, XSLT files etc). 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 Synapse at runtime, and cached appropriately as per its definition in the registry. Once the cache expires, Synapse would re-check the meta information for the definition and re-load the sequence definition if necessary and re-cache it again.

Execute the client as follows.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/

Go through the mediation debug logs to see how Synapse has dynamically loaded the sequence configurations from the registry.

[HttpServerWorker-1] DEBUG SimpleURLRegistry - ==> Repository fetch of resource with key : sequence/dynamic_seq_1.xml ... [HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator <dynamic_sequence> :: mediate() ... [HttpServerWorker-1] INFO LogMediator - message = *** Test Message 1 ***

Now if you execute the client immediately (i.e. within 15 seconds of the last execution) you will notice that the sequence is not reloaded. If you edit the sequence definition in repository/conf/sample/resources/sequence/dynamic_seq_1.xml (i.e. 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 (i.e. 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 Synapse from the following log messages.

[HttpServerWorker-1] DEBUG SimpleURLRegistry - ==> Repository fetch of resource with key : sequence/dynamic_seq_1.xml ... [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 suit the environment and the needs.

Back to Catalog