NAME
Queue::Q4Pg::Lite - Simple message queue using PostgreSQL
SYNOPSIS
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 );
DESCRIPTION
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.
METHODS
new
Creates a new Queue::Q4Pg::Lite instance. Normally you should use connect() instead.
connect
Connects to the target database.
my $q = Queue::Q4Pg::Lite->connect(
connect_info => [
'dbi:Pg:dbname=q4pg',
]
);
next($table, [$where]);
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 } });
fetch_hashref
Fetches the next available row as hashref.
my $hashref = $q->fetch_hashref();
ack
Delete the fetched row from table.
If You don't call ack(), the fetched row is not deleted from table.
insert($table, \%field)
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 });
clear($table);
Deletes everything the specified queue.
dbh
Returns the database handle after making sure that it's connected.
disconnect
Disconnects.
AUTHOR
FUJIWARA Shunichiro <fujiwara@cpan.org>
SEE ALSO
Queue::Q4M, SQL::Abstract, http://d.hatena.ne.jp/n_shuyo/20090415/mq
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.