NAME
AnyEvent::RabbitMQ::Fork - Run AnyEvent::RabbitMQ inside AnyEvent::Fork(::RPC)
SYNOPSIS
use AnyEvent::RabbitMQ::Fork;
my $cv = AnyEvent->condvar;
my $ar = AnyEvent::RabbitMQ::Fork->new->load_xml_spec()->connect(
host => 'localhost',
port => 5672,
user => 'guest',
pass => 'guest',
vhost => '/',
timeout => 1,
tls => 0, # Or 1 if you'd like SSL
tune => { heartbeat => 30, channel_max => $whatever, frame_max = $whatever },
on_success => sub {
my $ar = shift;
$ar->open_channel(
on_success => sub {
my $channel = shift;
$channel->declare_exchange(
exchange => 'test_exchange',
on_success => sub {
$cv->send('Declared exchange');
},
on_failure => $cv,
);
},
on_failure => $cv,
on_close => sub {
my $method_frame = shift->method_frame;
die $method_frame->reply_code, $method_frame->reply_text;
},
);
},
on_failure => $cv,
on_read_failure => sub { die @_ },
on_return => sub {
my $frame = shift;
die "Unable to deliver ", Dumper($frame);
},
on_close => sub {
my $why = shift;
if (ref($why)) {
my $method_frame = $why->method_frame;
die $method_frame->reply_code, ": ", $method_frame->reply_text;
}
else {
die $why;
}
},
);
print $cv->recv, "\n";
DESCRIPTION
This module is mean't to be a close to a drop-in facade for running AnyEvent::RabbitMQ in a background process via AnyEvent::Fork::RPC.
Tha main use case is for programs where other operations block with little control due to difficulty/laziness. In this way, the process hosting the connection RabbitMQ is doing nothing else but processing messages.
CONSTRCTOR
my $ar = AnyEvent::RabbitMQ::Fork->new();
Options
METHODS
- load_xml_spec([$amqp_spec_xml_path])
-
Declare and load the AMQP Specification you wish to use. The default is to use version 0.9.1 with RabbitMQ specific extensions.
Returns: $self
- connect(%opts)
-
Open connection to an AMQP server to begin work.
Arguments:
- host
- port
- user
- pass
- vhost
- timeout TCP timeout in seconds. Default: use AnyEvent::Socket default
- tls Boolean to use SSL/TLS or not. Default: 0
- tune Hash: (values are negotiated with the server)
- on_success Callback when the connection is successfully established.
- on_failure Called when a failure occurs over the lifetime of the connection.
- on_read_failure Called when there is a problem reading response from the server.
- on_return Called if the server returns a published message.
- on_close Called when the connection is closed remotely.
Returns: $self
- open_channel(%opts)
-
Open a logical channel which is where all the AMQP fun is.
Arguments:
- close(%opts)
-
Close this connection.
AUTHOR
William Cox <mydimension@gmail.com>
COPYRIGHT
Copyright (c) 2014, the above named author(s).
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.