<a id="maven_plugin_expectation_initializer_class" class="anchor" href="#maven_plugin_expectation_initializer_class">&nbsp;</a>

<h2>Clustering MockServer</h2>

<p>MockServer supports a <a href="/mock_server/performance.html">very high request throughput</a>, however if a higher request per second rate is required it is possible to cluster MockServer so that all nodes share expectations.</p>
<p>Although expectations are clustered, currently there is no support for clustering the MockServer log therefore request verifications will only work against the node that received the request.</p>

<p>To create a MockServer cluster all instances need to:</p>
<ul>
    <li>share a read-write file system i.e. same physical / virtual machine, <a target="_blank" href="https://en.wikipedia.org/wiki/Network_File_System" rel="noopener noreferrer">NFS</a>, <a target="_blank" href="https://aws.amazon.com/efs/" rel="noopener noreferrer">AWS EFS</a>, <a target="_blank" href="https://docs.microsoft.com/en-us/azure/storage/files/" rel="noopener noreferrer">Azure Files</a>, etc</li>
    <li>configure identical <a href="/mock_server/initializing_expectations.html#expectation_initializer_json">expectation initialiser</a> and <a href="/mock_server/persisting_expectations.html">expectation persistence</a></li>
    <li>bind to a free port i.e. separate ports if on same physical / virtual machine</li>
</ul>

<p>Each node could be configured as follows (adjusting the port as necessary):</p>

<pre class="prettyprint lang-javascript code"><code class="code">MOCKSERVER_WATCH_INITIALIZATION_JSON=true \
MOCKSERVER_INITIALIZATION_JSON_PATH=mockserverInitialization.json \
MOCKSERVER_PERSIST_EXPECTATIONS=true \
MOCKSERVER_PERSISTED_EXPECTATIONS_PATH=mockserverInitialization.json \
java -jar ~/Downloads/mockserver-netty-{{ site.mockserver_version }}-no-dependencies.jar -serverPort 1080 -logLevel INFO</code></pre>

<p>or</p>

<pre class="prettyprint lang-javascript code"><code class="code">java \
-Dmockserver.watchInitializationJson=true \
-Dmockserver.initializationJsonPath=mockserverInitialization.json \
-Dmockserver.persistExpectations=true \
-Dmockserver.persistedExpectationsPath=mockserverInitialization.json \
-jar ~/Downloads/mockserver-netty-{{ site.mockserver_version }}-no-dependencies.jar -serverPort 1080 -logLevel INFO</code></pre>
