login | register
Sun 20 of Jul, 2008 [07:43 UTC]

voip-info.org

Discuss [7] History

Asterisk RealTime Queue

Created by: knielsen,Last modification on Tue 17 of Jun, 2008 [13:13 UTC] by bcnit

Asterisk RealTime Queues


The queue application supports dynamic realtime. With dynamic realtime, the queue definition and member list will be reloaded each time a caller joins the queue. Thus queues can be updated in the database and the changes will be immediately visible without the need for an explicit reload.

It is possible to mix statically and dynamically defined queues. If a queue is defined in both static and dynamic realtime, the static version is used. The agent login feature currently only works for static queues though (a similar effect can be achieved with dynamic queues simply by inserting an appropriate row for a new member).

Extconfig.conf Setup

Add the following lines (changing of family names isn't allowed):


queues => mysql,asterisk,queue_table
queue_members => mysql,asterisk,queue_member_table


This example uses MySQL, but other realtime drivers (eg. ODBC) also work. The database containing the queue definitions is asterisk in this example, and the tables are called queue_table and queue_member_table.

Database Tables


Here are suitable MySQL table definitions for realtime queues. First the table defining each queue, with one row per queue.

CREATE TABLE queue_table (
 name VARCHAR(128) PRIMARY KEY,
 musiconhold VARCHAR(128),
 announce VARCHAR(128),
 context VARCHAR(128),
 timeout INT(11),
 monitor_join BOOL,
 monitor_format VARCHAR(128),
 queue_youarenext VARCHAR(128),
 queue_thereare VARCHAR(128),
 queue_callswaiting VARCHAR(128),
 queue_holdtime VARCHAR(128),
 queue_minutes VARCHAR(128),
 queue_seconds VARCHAR(128),
 queue_lessthan VARCHAR(128),
 queue_thankyou VARCHAR(128),
 queue_reporthold VARCHAR(128),
 announce_frequency INT(11),
 announce_round_seconds INT(11),
 announce_holdtime VARCHAR(128),
 retry INT(11),
 wrapuptime INT(11),
 maxlen INT(11),
 servicelevel INT(11),
 strategy VARCHAR(128),
 joinempty VARCHAR(128),
 leavewhenempty VARCHAR(128),
 eventmemberstatus BOOL,
 eventwhencalled BOOL,
 reportholdtime BOOL,
 memberdelay INT(11),
 weight INT(11),
 timeoutrestart BOOL,
 periodic_announce VARCHAR(50),
 periodic_announce_frequency INT(11),
 ringinuse BOOL
);



This table has a column for each possible queue parameter. Except for the mandatory name column, all columns are optional, and only the columns actually used need be included. Likewise, more columns may be added if the queue application is later extended with more parameters. A NULL value for a column indicates an unset parameter.

If you are using mysql 3.2.5X or lower the BOOL don't work so you have to simulate the behavior of the boolean with a tinyint(1) where 0 = false and 1 = true. that will change the structure to

CREATE TABLE queue_table (
 name VARCHAR(128) PRIMARY KEY,
 musiconhold VARCHAR(128),
 announce VARCHAR(128),
 context VARCHAR(128),
 timeout INT(11),
 monitor_join tinyint(1),
 monitor_format VARCHAR(128),
 queue_youarenext VARCHAR(128),
 queue_thereare VARCHAR(128),
 queue_callswaiting VARCHAR(128),
 queue_holdtime VARCHAR(128),
 queue_minutes VARCHAR(128),
 queue_seconds VARCHAR(128),
 queue_lessthan VARCHAR(128),
 queue_thankyou VARCHAR(128),
 queue_reporthold VARCHAR(128),
 announce_frequency INT(11),
 announce_round_seconds INT(11),
 announce_holdtime VARCHAR(128),
 retry INT(11),
 wrapuptime INT(11),
 maxlen INT(11),
 servicelevel INT(11),
 strategy VARCHAR(128),
 joinempty VARCHAR(128),
 leavewhenempty VARCHAR(128),
 eventmemberstatus tinyint(1),
 eventwhencalled tinyint(1),
 reportholdtime tinyint(1),
 memberdelay INT(11),
 weight INT(11),
 timeoutrestart tinyint(1),
 ringinuse tinyint(1)

);



As a convenience, it is permitted (but not required) to use underscore "_" instead of dash "-" in column names, since this is easier to handle in SQL.

The member table has a row for each member in a queue:

CREATE TABLE queue_member_table (
 uniqueid INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
 membername varchar(40),
 queue_name varchar(128),
 interface varchar(128),
 penalty INT(11),
 paused BOOL,
 UNIQUE KEY queue_interface (queue_name, interface)
);


One may add a foreign key from queue_name in the member table to name in the queue table, if so desired.

The values that go in the table for the fields "interface" and "penalty" are for example as shown below

interface= Agent/1112
penalty = 2

Set the [general] context in the queues.conf file

It was previously stated here that you need to add realtime_family in queues.conf, but you actually don't need to. App_queue always uses family names "queues" and "queue_members"


Using it


Define a queue by inserting a row in the queue table, and add members by inserting rows in the queue member table. The new queue should be immediately available for joining with the Queue() application command.

Note: realtime queues and queue members will be re-read when using Queue application, QUEUE_MEMBER_COUNT function, or CLI command "queue show QUEUENAME". Note that "queue show" does NOT re-load the queue data and will display cached information.


Further development


The mantis bug describing the implementation of realtime queue is bug 4037. This bug includes some discussion on how to extend dynamic queues to also work with the member login feature.

See also



Comments

Comments Filter
222

333Realtime SIP agent locate across server

by 850t, Thursday 24 of January, 2008 [03:55:01 UTC]
can realtime agent (I use sip user here) be across server?
222

333Can please any one tell me what other data will be inserted in realtime queue table

by waseem, Tuesday 20 of November, 2007 [06:59:15 UTC]
Can please any one tell me what other data will be inserted in realtime queue table i.e what will be inserted in musiconhold, queue_youarenext, queue_thereare, queue_callswaiting, queue_holdtime, queue_minutes, queue_seconds, queue_lessthan, queue_thankyou, queue_reporthold , announce_frequency, announce_round_seconds, announce_holdtime columns if we want to use these features.

Thanks
222

333How to create realtime agents

by waseem, Friday 13 of July, 2007 [11:16:18 UTC]
This method of realtime queues worked but only for queues. We have to define agents statilcally in agents.conf can any one take me that how to add agents dynamically.
222

333Where is periodic-announce capability?

by afazio, Tuesday 04 of April, 2006 [00:52:29 UTC]
I've noticed that there aren't any fields created in the above SQL queries for the periodic_announce_frequency and periodic_announce options. Is this not supported? I altered the tables to include the said fields and they do not seem to be recognized...
222

333Points to note about RealTime queues...

by nad, Friday 31 of March, 2006 [21:41:02 UTC]
Tested on version 1.2.6:

1. The database is only queried when someone joins a queue, If I join a queue with two members configured in the members table and a member is removed from the table while I'm in the queue I won't know that they have been removed until another caller joins the queue and so will continue calling both members until the other caller joins the queue.

2. Even with 'persistentmembers = yes' in queues.conf queue member status is NOT kept across restarts or reloads :(

3. If Asterisk is reloaded while I'm waiting in a queue the queue I'm in becomes orphaned. I continue calling the members that were present when Asterisk was reloaded but new callers will join a parallel queue which causes congestion when both queues try to call out to the same member and means the number of calls waiting in the queue are inaccurate.

IMHO issue 1 can be solved by re-querying the database at regular intervals dependant on the calling strategy used. I believe issues 2 & 3 are bugs and require fixing to bring them in line with people's expectations of the queue functionality.
222

333Realtime needs reload

by nizon, Tuesday 21 of February, 2006 [04:28:50 UTC]
I seem to be having the same problem, I need to reload asterisk before changes to the queue take effect.
222

333Really Realtime ?

by nobbi711, Friday 03 of February, 2006 [13:48:42 UTC]
It seems that changes to sql tables are not recognized until a relod is performed.
Tested on Asterisk 1.2.4

Example:

I changed the strategy field in the sql table queue_table.
The behavior was that until a reload or complete Asterisk restart happened,
the old setting for strategy was used.

Any Ideas ?