The priority based mediation is implemented in two levels in WSO2 ESB:
From the users perspective, key to any priority mediation is to determine the priority of an incoming message.
At the message mediation layer, this can be done using content filters. This means the full power of ESB configuration language is available to the user for determining the priority of a given message. For example, a message may contain an element called "priority" and depending on its value the priority can be determined.
At the HTTP layer, user has access to HTTP headers, HTTP parameters and URL values. By looking at these values, user can determine the priority of a given message.
The priority mediation implementation is based on
ThreadPoolExecutor accepts a
BlockingQueue implementation. A custom blocking queue that can be used to order the jobs based on priority was implemented.
ThreadPoolExecutor starts queuing only when the all the core threads are busy. Every message should get equal priority until all the core threads are used.
BlockingQueue uses multiple queues for accepting jobs with different priorities. Once jobs are put into the queue, it uses an pluggable algorithm for choosing the next job. The default algorithm chooses the jobs based on a priority based round robin algorithm. For example, lets say we have two priorities, 10 and 1. This algorithm tries to fetch 10 items with priority 10 and then 1 item with the priority 1.
Priority executors can be used to execute sequences with a given priority. Priority executors are used in high load scenarios, where user wants to execute different sequences with different priorities. This allows user to control the resources allocated to executing sequences and prevent high priority messages from getting delayed and dropped. A priority has a valid meaning comparing to other priorities specified. For example, if there are two priorities with value 10 and 1, message with priority 10 will get 10 times more resources than messages with priority 1.
Core priority executors' attributes:
An executor should have at least two or more queues. If only one queue is used, there is no point in using a priority executor.
If the queues has unlimited length, no more than core threads will be used.
corethreads, they will be in active for the
keep-alivetime only. After the
keep-alivetime, those threads will be be removed from the system.