MQUEUE module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”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.
Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The following modules must be loaded before this module:
- None.
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- None.
Exported Parameters
Section titled “Exported Parameters”db_url (str)
Section titled “db_url (str)”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).
...modparam("mqueue", "db_url", "mysql://opensips:opensipsrw@localhost/opensips")
# 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 mqueueCREATE TABLE mqueue_name (id INTEGER PRIMARY KEY AUTOINCREMENT,key character varying(64) DEFAULT "" NOT NULL,val character varying(4096) DEFAULT "" NOT NULL);...mqueue (string)
Section titled “mqueue (string)”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).
- addmode: how to add new (key,value) pairs.
- 0: Will push all new (key,value) pairs at the end of the queue. (default)
- 1: Will keep oldest (key,value) pair in the queue, based on the key.
- 2: Will keep newest (key,value) pair in the queue, based on the key.
The parameter can be set many times, each holding the definition of one queue.
...modparam("mqueue", "mqueue", "name=myq;size=20;")modparam("mqueue", "mqueue", "name=myq;size=10000;addmode=2")modparam("mqueue", "mqueue", "name=qaz")modparam("mqueue", "mqueue", "name=qaz;addmode=1")...Exported Functions
Section titled “Exported Functions”mq_add(queue, key, value)
Section titled “mq_add(queue, key, value)”Add a new item (key, value) in the queue. If max size of queue is exceeded, the oldest one is removed.
...mq_add("myq", "$rU", "call from $fU");...mq_fetch(queue)
Section titled “mq_fetch(queue)”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).
...while(mq_fetch("myq")){ xlog("$mqk(myq) - $mqv(myq)\n");}...mq_pv_free(queue)
Section titled “mq_pv_free(queue)”Free the item fetched in pseudo-variables. It is optional, a new fetch frees the previous values.
...mq_pv_free("myq");...mq_size(queue)
Section titled “mq_size(queue)”Returns the current number of elements in the mqueue.
If the mqueue is empty, the function returns -1. If the mqueue is not found, the function returns -2.
...$var(q_size) = mq_size("queue");xlog("L_INFO", "Size of queue is: $var(q_size)\n");...Exported MI Functions
Section titled “Exported MI Functions”mq_get_size
Section titled “mq_get_size”Get the size of a memory queue.
Parameters:
- name
...opensips-cli -x mq_get_size xyz...mq_fetch
Section titled “mq_fetch”Fetch one (or up to limit) key-value pair from a memory queue.
Parameters:
- name
- limit limit
...opensips-cli -x mq_fetch xyz...mq_get_sizes
Section titled “mq_get_sizes”Get the size for all memory queues.
Parameters: none
...opensips-cli -x mq_get_sizes...Exported Pseudo-Variables
Section titled “Exported Pseudo-Variables”$mqk(mqueue)
Section titled “$mqk(mqueue)”The variable is read-only and returns the most recent item key fetched from the specified mqueue.
$mqv(mqueue)
Section titled “$mqv(mqueue)”The variable is read-only and returns the most recent item value fetched from the specified mqueue.
$mq_size(mqueue)
Section titled “$mq_size(mqueue)”The variable is read-only and returns the size of the specified mqueue.
Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Ovidiu Sas (@ovidiusas) | 19 | 2 | 1843 | 34 |
| 2. | Stefan Darius (@dariusstefan) | 9 | 5 | 337 | 55 |
| 3. | Razvan Crainea (@razvancrainea) | 4 | 2 | 76 | 17 |
| 4. | Alexandra Titoc | 3 | 1 | 13 | 9 |
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 2. | Razvan Crainea (@razvancrainea) | Feb 2025 - Jun 2026 |
| 3. | Alexandra Titoc | Sep 2024 - Sep 2024 |
| 4. | Ovidiu Sas (@ovidiusas) | Feb 2024 - Feb 2024 |
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Ovidiu Sas (@ovidiusas).
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0