Skip to content

Instantly share code, notes, and snippets.

@cooldaemon
Created March 12, 2010 15:09
Show Gist options
  • Save cooldaemon/330391 to your computer and use it in GitHub Desktop.
Save cooldaemon/330391 to your computer and use it in GitHub Desktop.
Reconnection test for Net::RabbitFoot
% rabbitmq-server -detached
% perl test.pl
% rabbitmqctl list_connections pid
Listing connections ...
<rabbit@xxx.711.0>
...done.
% rabbitmqctl close_connection "<rabbit@xxx.711.0>" "go away"
use Coro;
use Net::RabbitFoot;
use Data::Dumper;
my $rf = Net::RabbitFoot->new(
# verbose => 1,
)->load_xml_spec(
Net::RabbitFoot::default_amqp_spec()
);
consume($rf,);
exit;
sub consume {
my ($rf,) = @_;
my $main = $Coro::current;
my $done = 0;
$rf->connect(
host => 'localhosti',
port => 5672,
user => 'guest',
port => 'guest',
vhost => '/',
on_close => unblock_sub {
print Dumper([@_]), "\n";
$done = 2;
$main->ready;
schedule;
}
);
my $ch = $rf->open_channel();
$ch->declare_queue(queue => 'test_q');
$ch->consume(
queue => 'test_q',
on_consume => unblock_sub {
my $response = shift;
print $response->{body}->payload, "\n";
$done = 1;
$main->ready;
schedule;
},
);
schedule while !$done;
if ($done == 2) {
print 'reconnect!!!!', "\n";
consume($rf,);
}
$rf->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment