App-RabbitTail
view release on metacpan or search on metacpan
lib/App/RabbitTail.pm view on Meta::CPAN
package App::RabbitTail;
use Moose;
use Net::RabbitFoot 1.03;
use App::RabbitTail::FileTailer;
use AnyEvent;
use Data::Dumper;
use Moose::Autobox;
use MooseX::Types::Moose qw/ArrayRef Str Int/;
use Try::Tiny qw/ try catch /;
use namespace::autoclean;
our $VERSION = '0.002';
$VERSION = eval $VERSION;
with 'MooseX::Getopt';
has filename => (
isa => ArrayRef[Str],
is => 'ro',
cmd_aliases => ['fn'],
required => 1,
traits => ['Getopt'],
);
has routing_key => (
isa => ArrayRef[Str],
is => 'ro',
cmd_aliases => ['rk'],
default => sub { [ '#' ] },
traits => ['Getopt'],
);
has max_sleep => (
isa => Int,
is => 'ro',
default => 10,
documentation => 'The max sleep time between trying to read a line from an input file',
);
has _cv => (
is => 'ro',
lazy => 1,
default => sub { AnyEvent->condvar },
clearer => '_clear_cv',
);
my $rf = Net::RabbitFoot->new(
varbose => 1,
)->load_xml_spec();
has _rf => (
isa => 'Net::RabbitFoot',
is => 'ro',
lazy => 1,
builder => '_build_rf',
clearer => '_clear_rf',
);
sub _build_rf {
my ($self) = @_;
my $rf_conn;
while (!$rf_conn) {
try {
$rf_conn = $rf->connect(
on_close => sub {
warn(sprintf("RabbitMQ connection to %s:%s closed!\n", $self->host, $self->port));
$self->_clear_ch;
$self->_clear_rf;
$self->_cv->send("ARGH");
},
( run in 0.785 second using v1.01-cache-2.11-cpan-df04353d9ac )