table of contents
QUEUE_SPLITTER3(1) | QUEUE_SPLITTER3(1) |
NAME¶
queue_splitter3 - PgQ consumer that transports events from one queue into several target queues
SYNOPSIS¶
queue_splitter3 [switches] config.ini
DESCRIPTION¶
queue_spliter is PgQ consumer that transports events from source queue into several target queues. ev_extra1 field in each event shows into which target queue it must go. (pgq.logutriga() puts there the table name.)
One use case is to move events from OLTP database to batch processing server. By using queue spliter it is possible to move all kinds of events for batch processing with one consumer thus keeping OLTP database less crowded.
QUICK-START¶
Basic queue_splitter setup and usage can be summarized by the following steps:
$ pgqadm.py ticker.ini create <queue>
$ queue_splitter3 queue_splitter_sourcedb_sourceq_targetdb.ini -d
CONFIG¶
Common configuration parameters¶
job_name
pidfile
logfile
loop_delay
connection_lifetime
use_skylog
Common PgQ consumer parameters¶
queue_name
consumer_name
queue_splitter parameters¶
src_db
dst_db
Example config file¶
[queue_splitter3] job_name = queue_spliter_sourcedb_sourceq_targetdb
src_db = dbname=sourcedb dst_db = dbname=targetdb
pgq_queue_name = sourceq
logfile = ~/log/%(job_name)s.log pidfile = ~/pid/%(job_name)s.pid
COMMAND LINE SWITCHES¶
Following switches are common to all skytools.DBScript-based Python programs.
-h, --help
-q, --quiet
-v, --verbose
-d, --daemon
--ini
Following switches are used to control already running process. The pidfile is read from config then signal is sent to process id specified there.
-r, --reload
-s, --stop
-k, --kill
USECASE¶
How to to process events created in secondary database with several queues but have only one queue in primary database. This also shows how to insert events into queues with regular SQL easily.
CREATE SCHEMA queue; CREATE TABLE queue.event1 (
-- this should correspond to event internal structure
-- here you can put checks that correct data is put into queue
id int4,
name text,
-- not needed, but good to have:
primary key (id) ); -- put data into queue in urlencoded format, skip actual insert CREATE TRIGGER redirect_queue1_trg BEFORE INSERT ON queue.event1 FOR EACH ROW EXECUTE PROCEDURE pgq.logutriga('singlequeue', 'SKIP'); -- repeat the above for event2
-- now the data can be inserted: INSERT INTO queue.event1 (id, name) VALUES (1, 'user');
If the queue_splitter is put on "singlequeue", it spreads the event on target to queues named "queue.event1", "queue.event2", etc. This keeps PgQ load on primary database minimal both CPU-wise and maintenance-wise.
09/28/2016 |