blob: 99df29891ffadce9d9018c624f6084c101ba3bb9 [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 651</title>
</properties>
<body>
<section name="Sample 651: Priority Based Dispatching at Transport Level">
<p>
For this sample we will be using the same Synapse configuration used in
<a href="sample150.html">sample 150</a>. In addition we will be using the following
priority configuration for the Synapse NHTTP transport.
</p>
<div class="xmlConf">&lt;priorityConfiguration&gt;
&lt;priorityExecutor&gt;
&lt;!-- two priorities specified with priority 10 and 1. Both priority messages has a queue depth of 100 --&gt;
&lt;queues isFixedCapacity=&quot;true&quot; nextQueue=&quot;org.apache.synapse.commons.executors.PRRNextQueueAlgorithm&quot;&gt;
&lt;queue size=&quot;100&quot; priority=&quot;10&quot;/&gt;
&lt;queue size=&quot;100&quot; priority=&quot;1&quot;/&gt;
&lt;/queues&gt;
&lt;!-- these are the default values, values are put here to show their availability --&gt;
&lt;threads core=&quot;20&quot; max=&quot;100&quot; keep-alive=&quot;5&quot;/&gt;
&lt;/priorityExecutor&gt;
&lt;!-- if a message comes that we cannot determine priority, we set a default priority of 1 --&gt;
&lt;conditions defaultPriority=&quot;1&quot;&gt;
&lt;condition priority=&quot;10&quot;&gt;
&lt;!-- check for the header named priority --&gt;
&lt;equal type=&quot;header&quot; source=&quot;priority&quot; value=&quot;5&quot;/&gt;
&lt;/condition&gt;
&lt;condition priority=&quot;1&quot;&gt;
&lt;equal type=&quot;header&quot; source=&quot;priority&quot; value=&quot;1&quot;/&gt;
&lt;/condition&gt;
&lt;/conditions&gt;
&lt;/priorityConfiguration&gt;</div>
<subsection name="Objective">
<p>
Demonstrate priority based dispatching capabilities of the Synapse NHTTP
transport
</p>
</subsection>
<subsection name="Pre-requisites">
<p>
<ul>
<li>
Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
</li>
<li>
Open axis2.xml file in repository/conf directory and uncomment the
following parameter in the NHTTP transport receiver configuration.
<br/><strong>priorityConfigFile</strong>
<br/>Set the value to repository/conf/sample/resources/priority/priority-configuration.xml
</li>
<li>
Start Synapse using the configuration numbered 150 (repository/conf/sample/synapse_sample_150.xml)
<div class="command">
Unix/Linux: sh synapse.sh -sample 150<br/>
Windows: synapse.bat -sample 150
</div>
</li>
</ul>
</p>
</subsection>
<subsection name="Executing the Client">
<p>
Priority is applied only when synapse is loaded with enough messages to consume
all of its core worker threads. So to observe the priority based mediation, it is
required to use a load testing tool like JMeter, SOAP UI or Apache bench.
</p>
<p>
In this sample, client should send a HTTP header that specifies the priority of
the message.This header name is 'priority'. This header is retrieved in the synapse
configuration using the $trp:priority XPath expression. Then it is matched against
the value 1. If it has the value 1, message is executed with priority 1. Otherwise
the message is executed with priority 10.
</p>
<p>
Messages with different priorities are put into different priority queues. Then they
are mediated in a manner so that high priority messages are always processed first.
</p>
<p>
Here are two sample SOAP requests that can be used to invoke the service using a
tool like JMeter, or Apache Bench. For SOAP UI, user can use the WSDL
repository/conf/sample/resources/proxy/sample_proxy_1.wsdl to create the request.
The only difference between the two requests shown here is the symbol. One
has the symbol as IBM and other has MSFT. For one type of requests set the priority
header to 1 and for the next set the priority header to 10. Then load Synapse with
a large volume of traffic consisting of both types of requests using the load testing tool.
Back end Axis2 server prints the symbol of the incoming requests. User should be
able to see more of the high priority symbol.
</p>
<div class="xmlConf">&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
&lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
&lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
&lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
&lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
&lt;/soapenv:Header&gt;
&lt;soapenv:Body&gt;
&lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
&lt;m0:request&gt;
&lt;m0:symbol&gt;IBM&lt;/m0:symbol&gt;
&lt;/m0:request&gt;
&lt;/m0:getQuote&gt;
&lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</div>
<div class="xmlConf">&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
&lt;soapenv:Header xmlns:wsa=&quot;http://www.w3.org/2005/08/addressing&quot;&gt;
&lt;wsa:To&gt;http://localhost:8281/services/SimpleStockQuoteService&lt;/wsa:To&gt;
&lt;wsa:MessageID&gt;urn:uuid:1B57D0B0BF770678DE1261165228620&lt;/wsa:MessageID&gt;
&lt;wsa:Action&gt;urn:getQuote&lt;/wsa:Action&gt;
&lt;/soapenv:Header&gt;
&lt;soapenv:Body&gt;
&lt;m0:getQuote xmlns:m0=&quot;http://services.samples&quot;&gt;
&lt;m0:request&gt;
&lt;m0:symbol&gt;MSFT&lt;/m0:symbol&gt;
&lt;/m0:request&gt;
&lt;/m0:getQuote&gt;
&lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;</div>
<p>
In this sample, priority based mediation takes place at the transport level
itself (before the message is even received by the mediation engine). High
priority messages will reach the service bus first.
</p>
</subsection>
</section>
<p><a href="../samples.html">Back to Catalog</a></p>
</body>
</document>