Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: AnyEvent::RabbitMQ not connecting?

by Khen1950fx (Canon)
on Oct 09, 2014 at 16:02 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103316]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found