Created
March 12, 2010 15:09
-
-
Save cooldaemon/330391 to your computer and use it in GitHub Desktop.
Reconnection test for Net::RabbitFoot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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