NAME
AnyEvent::Stomper::Pool - Connection pool for AnyEvent::Stomper
SYNOPSIS
use AnyEvent;
use AnyEvent::Stomper::Pool;
my $pool = AnyEvent::Stomper::Pool->new(
nodes => [
{ host => 'mq-broker-1.com', port => 61613 },
{ host => 'mq-broker-2.com', port => 61613 },
{ host => 'mq-broker-3.com', port => 61613 },
],
login => 'guest',
passcode => 'guest',
);
my $stomper = $pool->random;
my $cv = AE::cv;
$stomper->subscribe(
id => 'foo',
destination => '/queue/foo',
{ on_receipt => sub {
my $err = $_[1];
if ( defined $err ) {
warn $err->message . "\n";
$cv->send;
return;
}
$stomper->send(
destination => '/queue/foo',
body => 'Hello, world!',
);
},
on_message => sub {
my $msg = shift;
my $body = $msg->body;
print "Consumed: $body\n";
$cv->send;
},
}
);
$cv->recv;
DESCRIPTION
AnyEvent::Stomper::Pool is connection pool for AnyEvent::Stomper. This module can be used to work with cluster of queue brokers.
CONSTRUCTOR
new( %params )
my $stomper = AnyEvent::Stomper::Pool->new(
nodes => [
{ host => 'mq-broker-1.com', port => 61613 },
{ host => 'mq-broker-2.com', port => 61613 },
{ host => 'mq-broker-3.com', port => 61613 },
],
login => 'guest',
passcode => 'guest',
vhost => '/',
heart_beat => [ 5000, 5000 ],
connection_timeout => 5,
lazy => 1,
reconnect_interval => 5,
on_connect => sub {
# handling...
},
on_disconnect => sub {
# handling...
},
on_error => sub {
my $err = shift;
# error handling...
},
);
- nodes => \@nodes
-
Specifies the list of nodes. Parameter should contain array of hashes. Each hash should contain
host
andport
elements. - login => $login
-
The user identifier used to authenticate against a secured STOMP server.
- passcode => $passcode
-
The password used to authenticate against a secured STOMP server.
- vhost => $vhost
-
The name of a virtual host that the client wishes to connect to.
- heart_beat => \@heart_beat
-
Heart-beating can optionally be used to test the healthiness of the underlying TCP connection and to make sure that the remote end is alive and kicking. The first number sets interval in milliseconds between outgoing heart-beats to the STOMP server.
0
means, that the client will not send heart-beats. The second number sets interval in milliseconds between incoming heart-beats from the STOMP server.0
means, that the client does not want to receive heart-beats.heart_beat => [ 5000, 5000 ],
Not set by default.
- connection_timeout => $connection_timeout
-
Specifies connection timeout. If the client could not connect to the node If enabled, the connection establishes at time when you will send the first command to the server. By default the connection establishes after calling of the
new
method. after specified timeout, theon_node_error
callback is called with theE_CANT_CONN
error. The timeout specifies in seconds and can contain a fractional part.connection_timeout => 10.5,
By default the client use kernel's connection timeout.
- lazy => $boolean
-
If enabled, the connection establishes at time when you will send the first command to the node. By default the connection establishes after calling of the
new
method.Disabled by default.
- reconnect_interval => $reconnect_interval
-
If the parameter is specified, the client will try to reconnect only after this interval. Commands executed between reconnections will be queued.
reconnect_interval => 5,
Not set by default.
- handle_params => \%params
-
Specifies AnyEvent::Handle parameters.
handle_params => { autocork => 1, linger => 60, }
Enabling of the
autocork
parameter can improve perfomance. See documentation on AnyEvent::Handle for more information. - on_node_connect => $cb->( $host, $port )
-
The
on_node_connect
callback is called when the connection to specific node is successfully established. To callback are passed two arguments: host and port of the node to which the client was connected.Not set by default.
- on_node_disconnect => $cb->( $host, $port )
-
The
on_node_disconnect
callback is called when the connection to specific node is closed by any reason. To callback are passed two arguments: host and port of the node from which the client was disconnected.Not set by default.
- on_node_error => $cb->( $err, $host, $port )
-
The
on_node_error
callback is called when occurred an error, which was affected on entire node (e. g. connection error or authentication error). Also theon_node_error
callback can be called on command errors if the command callback is not specified. To callback are passed three arguments: error object, and host and port of the node on which an error occurred.Not set by default.
METHODS
get( $host, $port )
Gets specified node.
nodes()
Gets all available nodes.
random()
Gets random node.
next()
Gets next node from nodes list cyclically.
force_disconnect()
The method for forced disconnection. All uncompleted operations will be aborted.
SEE ALSO
AUTHOR
Eugene Ponizovsky, <ponizovsky@gmail.com>
Sponsored by SMS Online, <dev.opensource@sms-online.com>
COPYRIGHT AND LICENSE
Copyright (c) 2016, Eugene Ponizovsky, SMS Online. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.