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

Riales has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've been trying to use AnyEvent::RabbitMQ to connect to a local RabbitMQ server to little success. From what I can tell, calling connect never returns--the connect_cb of AnyEvent::Socket::tcp_connect in AnyEvent::RabbitMQ never gets called.

In the RabbitMQ log, I can see that it begins accepting a connection but eventually just times out on the handshake:

=INFO REPORT==== 7-Oct-2014::20:56:52 === accepting AMQP connection <0.472.0> (127.0.0.1:58387 -> 127.0.0.1:5672 +) =ERROR REPORT==== 7-Oct-2014::20:57:02 === closing AMQP connection <0.472.0> (127.0.0.1:58387 -> 127.0.0.1:5672): {handshake_timeout,handshake}

Anybody have any clue what might be happening?

Thanks!

Replies are listed 'Best First'.
Re: AnyEvent::RabbitMQ not connecting?
by thanos1983 (Parson) on Oct 08, 2014 at 11:03 UTC

    Hello Riales,

    I am not familiar with AMQP but I read your post and some information online and seems really interesting. Can you provide us with sample of working code and the steps that you have followed so far and you have failed? I am installing the RabbitMQ Server on my system as we speak so I can try a few things.

    Quick question, why did you choose to use AnyEvent::RabbitMQ for a particular reason, and if so what is this reason?

    I am asking because I am not familiar with it, and as I was searching online, I found many modules regarding AMQP on Perl RabbitMQ.

    I will run a few test and get back to you as soon as I finish the installation process.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Thanks for taking the time to look into it!

      I actually initially chose Net::RabbitFoot, but it depends on a module that is deprecated with Perl 5.18 so I went to what Net::RabbitFoot uses internally, which is AnyEvent::RabbitMQ.

      Anyways, I'll get some code for you to take a look at tonight!

Re: AnyEvent::RabbitMQ not connecting?
by Khen1950fx (Canon) on Oct 09, 2014 at 16:02 UTC
    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.