Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: AnyEvent::RabbitMQ not connecting?

by Khen1950fx (Canon)
on Oct 09, 2014 at 16:02 UTC ( #1103316=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1103316]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2019-05-22 01:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (138 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!