Saturday, November 6, 2010

Best of New in Kamailio 3.1.0 - #11: Asynchronous message queues in config file

One of the main problems while trying to interact with other systems direct from your SIP server was that most of the time such operations are done in blocking mode.

Whether you want to do an http query, send an email, write to a storage system for a specific SIP event, that uses the time and resources of your SIP routing engine and you cannot afford blocking all application processes that handle SIP traffic.

There are a lot of reason you would like to do such operations, for example:
  • monitoring activity - notify when the rate of incoming SIP requests exceed a threshold - alert on flood
  • real time notifications to twitter, facebook or classic email for events such as missed calls or a particular user becomes online
  • logging purposes - write details about various situations to a storage system
Kamailio v3.1.0 pushed out a new module mqueue, which is message queue system that can be used directly in the configuration file. You can define as many queues as you want, read and write operations are safe even when done from different application processes. You can write a message from a process and read in another one.

For example, a typical usage is to start dedicated processes to consume messages from the queues. You can do that in configu using rtimer module - start separate processes that execute periodically a route block from config, where you process messages from queues.

Next is an example of usage:
  • the sip worker process writes in queue "alert" when pike modules triggers alert due to high traffic rate from same IP
  • process checks every 5 seconds checks if there are message in queue 'alert' and writes to syslog all the messages in the queue
modparam("rtimer", "timer",  "name=ta;interval=5;mode=1;")
modparam("rtimer", "exec", "timer=ta;route=QMALERT")
modparam("mqueue", "mqueue", "name=alert")

route {
if (!pike_check_req())
mq_add("alert", "$si:$sp", "pike flood detected [$rm] $fu => $ru");

route[QMALERT] {
xlog("L_ALERT","ALERT: src [$mqk(alert)] - $mqv(alert)\n");
Here you find the online documentation for mqueue module:

No comments:

Post a Comment