Closed le-garff-yoann closed 9 years ago
#!/usr/bin/perl
use 5.10.1;
use strict;
use warnings;
use AnyEvent::DateTime::Cron;
use AnyEvent::RabbitMQ;
use Data::Dumper qw/
Dumper
/;
my %ar_pros = (
host => 'localhost',
port => 5672,
user => 'guest',
pass => 'guest',
vhost => '/',
timeout => 1,
tls => 0,
tune => {
heartbeat => 30
},
on_success => sub {
my $ar = shift;
$ar->open_channel(
on_success => sub {
my $channel = shift;
# AnyEvent::RabbitMQ::Channel
},
on_failure => sub {
},
on_close => sub {
}
);
},
on_failure => sub {
},
on_read_failure => sub { warn @_ },
on_return => sub {
my $frame = shift;
},
on_close => sub {
}
);
my $ar;
my $cron = AnyEvent::DateTime::Cron->new(
quartz => 1
);
$cron->add(
'*/1 * * * * ?',
single => 1,
sub {
say 'Is connected ? ' . $ar->is_open();
}
);
$cron->add(
'15 * * * * ?',
sub {
say 'Connect';
$ar->connect(%ar_pros);
}
);
$cron->add(
'45 * * * * ?',
sub {
say 'Disconnect';
$ar->close();
}
);
$ar = AnyEvent::RabbitMQ->new()->load_xml_spec();
$cron->start()->recv()
__END__
6c2331cf119e89ff11c4934c5f91d609fd2e62f0
Switch from Net::AMQP::RabbitMQ to AnyEvent::RabbitMQ (non-blocking, TLS, ...).
Update the README (AnyEvent::RabbitMQ has some problems at installation (libxml2 binding)).