Sample 651: Priority Based Dispatching at Transport Level

For this sample we will be using the same Synapse configuration used in sample 150. In addition we will be using the following priority configuration for the Synapse NHTTP transport.

<priorityConfiguration> <priorityExecutor> <!-- two priorities specified with priority 10 and 1. Both priority messages has a queue depth of 100 --> <queues isFixedCapacity="true" nextQueue="org.apache.synapse.commons.executors.PRRNextQueueAlgorithm"> <queue size="100" priority="10"/> <queue size="100" priority="1"/> </queues> <!-- these are the default values, values are put here to show their availability --> <threads core="20" max="100" keep-alive="5"/> </priorityExecutor> <!-- if a message comes that we cannot determine priority, we set a default priority of 1 --> <conditions defaultPriority="1"> <condition priority="10"> <!-- check for the header named priority --> <equal type="header" source="priority" value="5"/> </condition> <condition priority="1"> <equal type="header" source="priority" value="1"/> </condition> </conditions> </priorityConfiguration>


Demonstrate priority based dispatching capabilities of the Synapse NHTTP transport


  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
  • Open axis2.xml file in repository/conf directory and uncomment the following parameter in the NHTTP transport receiver configuration.
    Set the value to repository/conf/sample/resources/priority/priority-configuration.xml
  • Start Synapse using the configuration numbered 150 (repository/conf/sample/synapse_sample_150.xml)
    Unix/Linux: sh -sample 150
    Windows: synapse.bat -sample 150

Executing the Client

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.

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.

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.

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.

<soapenv:Envelope xmlns:soapenv=""> <soapenv:Header xmlns:wsa=""> <wsa:To>http://localhost:8281/services/SimpleStockQuoteService</wsa:To> <wsa:MessageID>urn:uuid:1B57D0B0BF770678DE1261165228620</wsa:MessageID> <wsa:Action>urn:getQuote</wsa:Action> </soapenv:Header> <soapenv:Body> <m0:getQuote xmlns:m0="http://services.samples"> <m0:request> <m0:symbol>IBM</m0:symbol> </m0:request> </m0:getQuote> </soapenv:Body> </soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv=""> <soapenv:Header xmlns:wsa=""> <wsa:To>http://localhost:8281/services/SimpleStockQuoteService</wsa:To> <wsa:MessageID>urn:uuid:1B57D0B0BF770678DE1261165228620</wsa:MessageID> <wsa:Action>urn:getQuote</wsa:Action> </soapenv:Header> <soapenv:Body> <m0:getQuote xmlns:m0="http://services.samples"> <m0:request> <m0:symbol>MSFT</m0:symbol> </m0:request> </m0:getQuote> </soapenv:Body> </soapenv:Envelope>

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.

Back to Catalog