MessageQueue: Difference between revisions

From Yate Documentation
Jump to navigation Jump to search
No edit summary
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
MessageQueue API for JavaScript.
The MessageQueues is a mechanism for organizing YATE's messages in different queues, identified by message name and some specified filters.
 
This article explains how to create and use a MessageQueue in Javascript.<br>The purpose of messageQueue mechanism is to streamline the messages processing in Yate.
 
===How to create MessageQueue in Javascript ===


===Message.installHook()===
In JavaScript a MessageQueue can be created by calling Message.installHook() method.
In JavaScript a MessageQueue can be created by calling Message.installHook() method.


A description of MessageQueue behaviour can be found [http://docs.yate.ro/wiki/Messages#How_messages_are_processed here] .
Read the description of MessageQueue behaviour in [[Messages#How_messages_are_processed|messages page]] .


=== installHook parameters===
==== installHook parameters====


installHook parameters:
*processCallback - function, optional. The method that should process the messages skipping the engine handlers list.
*processCallback - function, optional. The method that should process the messages skipping the engine handlers list.
*msgName        - string, mandatory.  The message name for the queue filtering.
*msgName        - string, mandatory.  The message name for the queue filtering.
*workers        - integer, mandatory.  The number of workers that should be used for message processing.
*workers        - integer, mandatory.  The number of workers that should be used for message processing.
Line 18: Line 20:
===Examples===
===Examples===


#Creates a MessageQueue for engine.timer message with one processing thread.
1. Creates a MessageQueue for engine.timer message with one processing thread.
  installHook("engine.timer",1);
  installHook("engine.timer",1);


#Creates a MessageQueue for call.route message, who has called=123. Two processing threads will be created. When a message needs to be processed the callback method will be called.
2. Creates a MessageQueue for call.route message, who has called=123. Two processing threads will be created. When a message needs to be processed the callback method will be called.
 


  installHook(callback,"call.route",2,"called=123");
  installHook(callback,"call.route",2,"called=123");


#The same behaviour as above only that the trapCallback method will be called when in the queue exists more than 50 unprocessed messages
3. The same behaviour as above only that the trapCallback method will be called when in the queue exists more than 50 unprocessed messages


  installHook(callback,"call.route",2,trapCallback,50,"called=123");
  installHook(callback,"call.route",2,trapCallback,50,"called=123");


===When to use?===
===When to use?===
MessageQueue can be used:
* when you have a high number of a specific message that needs to be handled
* when handling a message implies sending more messages that need to be processed
* when you want to avoid using Yate's message queue
If you need to handle a specific message frequently or see that processing this message takes too long you might need to use a custom MessageQueue for that message.





Latest revision as of 10:45, 14 May 2013

The MessageQueues is a mechanism for organizing YATE's messages in different queues, identified by message name and some specified filters.

This article explains how to create and use a MessageQueue in Javascript.
The purpose of messageQueue mechanism is to streamline the messages processing in Yate.

How to create MessageQueue in Javascript

In JavaScript a MessageQueue can be created by calling Message.installHook() method.

Read the description of MessageQueue behaviour in messages page .

installHook parameters

  • processCallback - function, optional. The method that should process the messages skipping the engine handlers list.
  • msgName - string, mandatory. The message name for the queue filtering.
  • workers - integer, mandatory. The number of workers that should be used for message processing.
  • trapCallback - function, optional. The method that should be called when a queue overload is detected.
  • trapCount - integer, mandatory if trapCallback is present. The number of messages in the queue when we should be alerted.
  • filter - string, optional, can be repeated. Optional message filter. Should be in form 'name=value'.

Examples

1. Creates a MessageQueue for engine.timer message with one processing thread.

installHook("engine.timer",1);

2. Creates a MessageQueue for call.route message, who has called=123. Two processing threads will be created. When a message needs to be processed the callback method will be called.

installHook(callback,"call.route",2,"called=123");

3. The same behaviour as above only that the trapCallback method will be called when in the queue exists more than 50 unprocessed messages

installHook(callback,"call.route",2,trapCallback,50,"called=123");

When to use?

MessageQueue can be used:

  • when you have a high number of a specific message that needs to be handled
  • when handling a message implies sending more messages that need to be processed
  • when you want to avoid using Yate's message queue

If you need to handle a specific message frequently or see that processing this message takes too long you might need to use a custom MessageQueue for that message.


See also