Tatsumaki::MessageQueue - Message Queue system for Tatsumaki
To publish a message, you first create an instance of the message queue on a specific channel:
my $mq = Tatsumaki::MessageQueue->instance($channel); $mq->publish({ type => "message", data => $your_data, address => $self->request->address, time => scalar Time::HiRes::gettimeofday, });
Later, in a handler, you can poll for new messages:
my $mq = Tatsumaki::MessageQueue->instance($channel); my $client_id = $self->request->param('client_id') or Tatsumaki::Error::HTTP->throw(500, "'client_id' needed"); $mq->poll_once($client_id, sub { $self->write(\@_); $self->finish; });
Additionally, if you are using Multipart XmlHttpRequest (MXHR) you can use the event API, and run a callback each time a new message is published:
my $mq = Tatsumaki::MessageQueue->instance($channel); $mq->poll($client_id, sub { my @events = @_; for my $event (@events) { $self->stream_write($event); } });
Tatsumaki::MessageQueue is a simple message queue, storing all messages in memory, and keeping track of a configurable backlog. All polling requests are made with a $client_id, and the message queue keeps track of a buffer per client, to ensure proper message delivery.
$client_id
To configure the number of messages in the backlog, set $Tatsumaki::MessageQueue::BacklogLength. By default, this is set to 30.
$Tatsumaki::MessageQueue::BacklogLength
This method publishes a message into the message queue, for immediate consumption by all polling clients.
This is the event-driven poll mechanism, which accepts a callback as the second parameter. It will stream messages to the code ref passed in.
This method returns all messages since the last poll to the code reference passed as the second parameter.
Tatsuhiko Miyagawa
Tatsumaki
To install Tatsumaki, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tatsumaki
CPAN shell
perl -MCPAN -e shell install Tatsumaki
For more information on module installation, please visit the detailed CPAN module installation guide.