Copyright © 2010 Elena-Ramona Modroiu (asipto.com)
Copyright © 2018-2020 Julien chavanton, Flowroute
Table of Contents
List of Examples
db_url
parametermqueue
parametermq_add
usagemq_fetch
usagemq_pv_free
usagemq_size
usagemqueue.get_size
usagemqueue.fetch
usagemqueue.get_sizes
usageTable of Contents
The mqueue module offers a generic message queue system in shared memory for inter-process communication using the config file. One example of usage is to send time consuming operations to one or several timer processes that consumes items in the queue, without affecting SIP message handling in the socket-listening process.
There can be many defined queues. Access to queued values is done via pseudo variables.
The URL to connect to database for loading values in mqueue table at start up and/or saving values at shutdown.
Default value is NULL (do not connect).
Example 1.1. Set db_url
parameter
... modparam("mqueue", "db_url", "mysql://kamailio:kamailiorw@localhost/kamailio") # Example of table in sqlite, you have the set the fields to support the length according to the data that will be present in the mqueue CREATE TABLE mqueue_name ( id INTEGER PRIMARY KEY AUTOINCREMENT, key character varying(64) DEFAULT "" NOT NULL, val character varying(4096) DEFAULT "" NOT NULL ); ...
Definition of a memory queue
Default value is “none”.
Value must be a list of parameters: attr=value;...
Mandatory attributes:
name: name of the queue.
Optional attributes:
size: size of the queue. Specifies the maximum number of items in queue. If exceeded the oldest one is removed. If not set the queue will be limitless.
dbmode: If set to 1, the content of the queue is written to database table when the SIP server is stopped (i.e., ensure persistency over restarts). If set to 2, it is written at shutdown but not read at startup. If set to 3, it is read at sartup but not written at shutdown. Default value is 0 (no db table interaction).
The parameter can be set many times, each holding the definition of one queue.
Example 1.2. Set mqueue
parameter
... modparam("mqueue", "mqueue", "name=myq;size=20;") modparam("mqueue", "mqueue", "name=qaz") ...
Add a new item (key, value) in the queue. If max size of queue is exceeded, the oldest one is removed.
Take oldest item from queue and fill $mqk(queue) and $mqv(queue) pseudo variables.
Return: true on success (1); false on failure (-1) or no item fetched (-2).
Free the item fetched in pseudo-variables. It is optional, a new fetch frees the previous values.
Exported pseudo-variables are documented at https://www.kamailio.org/wiki/.
Get the size of a memory queue.
Parameters:
Fetch a key-value pair from a memory queue.
Parameters: