Queue::Q4Pg::Lite - Simple message queue using PostgreSQL
use Queue::Q4Pg::Lite; my $q = Queue::Q4Pg::Lite->connect( connect_info => [ 'dbi:Pg:dbname=mydb', $username, $password ], ); for (1..10) { $q->insert($table, \%fieldvals); } while ($q->next($table)) { my $cols = $q->fetch_hashref() print "col1 = $cols->{col1}, col2 = $cols->{col2}, col3 = $cols->{col3}\n"; $q->ack; } $q->disconnect; # Table schema requires id column. CREATE TABLE mq ( id SERIAL PRIMARY KEY, message TEXT );
Queue::Q4Pg::Lite is a simple message queue using PostgreSQL which supports pg_advisory_lock (version 8.2 or later).
This algorithms was invented by http://d.hatena.ne.jp/n_shuyo/20090415/mq .
Many codes copied from Queue::Q4M.
Creates a new Queue::Q4Pg::Lite instance. Normally you should use connect() instead.
Connects to the target database.
my $q = Queue::Q4Pg::Lite->connect( connect_info => [ 'dbi:Pg:dbname=q4pg', ] );
Blocks until the next item is available.
$where is same of arguments for SQL::Abstract->select($table, $col, $where)
# SELECT * FROM mq WHERE priority < 10; $q->next("mq", { priority => { "<", 10 } });
Fetches the next available row as hashref.
my $hashref = $q->fetch_hashref();
Delete the fetched row from table.
If You don't call ack(), the fetched row is not deleted from table.
Inserts into the queue. The first argument should be a scalar specifying a table name. The second argument is a hashref that specifies the mapping between column names and their respective values.
$q->insert($table, { col1 => $val1, col2 => $val2, col3 => $val3 });
Deletes everything the specified queue.
Returns the database handle after making sure that it's connected.
Disconnects.
FUJIWARA Shunichiro <fujiwara@cpan.org>
Queue::Q4M, SQL::Abstract, http://d.hatena.ne.jp/n_shuyo/20090415/mq
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Queue::Q4Pg::Lite, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Queue::Q4Pg::Lite
CPAN shell
perl -MCPAN -e shell install Queue::Q4Pg::Lite
For more information on module installation, please visit the detailed CPAN module installation guide.