http://www.perlmonks.org?node_id=1103316


in reply to AnyEvent::RabbitMQ not connecting?

I've never used it, but I'm game. Here's my first try. You'll note that instead of AnyEvent::RabbitMQ, I used AnyEvent::RabbitMQ::Fork:
#!/usr/bin/perl BEGIN { $ENV{'PERL_ANYEVENT_STRICT'} = 1; } use strict; use warnings; use FindBin; use Data::Dumper::Concise; my %server = ( product => undef, version => undef, ); my %conf = ( host => 'localhost', port => 5672, user => 'guest', pass => 'guest', vhost => q{/}, verbose => 1, ); eval { use IO::Socket::INET; my $socket = IO::Socket::INET->new( Proto => 'tcp', PeerAddr => $conf{'host'}, PeerPort => $conf{'port'}, Timeout => 1, ) or die 'Error connecting to AMQP Server!'; close $socket; }; use AnyEvent::RabbitMQ::Fork; my $ar = AnyEvent::RabbitMQ::Fork->new(verbose => $conf{'verbose'}); $ar->load_xml_spec(); my $done = AnyEvent->condvar; $ar->connect( (map {$_ => $conf{$_}} qw(host port user pass vhost)), tune => { frame_max => 2**17 }, timeout => 1, on_success => sub { my $ar = shift; $server{product} = $ar->server_properties->{product}; $server{version} = version->parse($ar->server_properties->{ver +sion}); $done->send; }, on_failure => failure_cb($done), on_return => sub { my $method_frame = shift->method_frame; die "return: ", $method_frame->reply_code, $method_frame->repl +y_text if $method_frame->reply_code; }, on_close => sub { my $method_frame = shift->method_frame; Carp::confess "close: ", $method_frame->reply_code, $method_fr +ame->reply_text if $method_frame->reply_code; }, ); sub failure_cb { my ($cv) = @_; return sub { $cv->send; }; } AnyEvent->condvar->recv;
You can find more examples at: rabbit-tutorials. The examples use Net::RabbitMQ, which has been more thoroughly tested than the AnyEvent modules. I hope that this helps you.