blob: 06354a05a9d2262548d641b07c4e53dbf7d67e64 [file] [log] [blame]
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<document>
<properties>
<title>Apache Synapse - Sample 9</title>
</properties>
<body>
<section name="Sample 9: Introduction to Dynamic Sequences with Registry">
<div class="xmlConf">&lt;definitions xmlns="http://ws.apache.org/ns/synapse"&gt;
&lt;registry provider="org.apache.synapse.registry.url.SimpleURLRegistry"&gt;
&lt;parameter name="root"&gt;file:./repository/conf/sample/resources/&lt;/parameter&gt;
&lt;parameter name="cachableDuration"&gt;15000&lt;/parameter&gt;
&lt;/registry&gt;
&lt;sequence name="main"&gt;
&lt;sequence key="sequence/dynamic_seq_1.xml"/&gt;
&lt;/sequence&gt;
&lt;/definitions&gt;</div>
<subsection name="Objective">
<p>
Demonstrating the ability to load sequence definitions dynamically from the
remote registry.
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
</li>
<li>
Start Synapse using the configuration numbered 9 (repository/conf/sample/synapse_sample_9.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 9<br/>
Windows: synapse.bat -sample 9
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
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.
</p>
<p>
Execute the client as follows.
</p>
<div class="command">ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/</div>
<p>
Go through the mediation debug logs to see how Synapse has dynamically loaded
the sequence configurations from the registry.
</p>
<div class="consoleOutput">[HttpServerWorker-1] DEBUG SimpleURLRegistry - ==&gt; Repository fetch of resource with key : sequence/dynamic_seq_1.xml
...
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;dynamic_sequence&gt; :: mediate()
...
[HttpServerWorker-1] INFO LogMediator - message = *** Test Message 1 ***</div>
<p>
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.
</p>
<div class="consoleOutput">[HttpServerWorker-1] DEBUG SimpleURLRegistry - ==&gt; Repository fetch of resource with key : sequence/dynamic_seq_1.xml
...
[HttpServerWorker-1] DEBUG SequenceMediator - Sequence mediator &lt;dynamic_sequence&gt; :: mediate()
...
[HttpServerWorker-1] INFO LogMediator - message = *** Test Message 2 ***</div>
<p>
The cache timeout could be tuned appropriately by configuring the URL registry
to suit the environment and the needs.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>