AnyEvent::Stomper::Pool - Connection pool for AnyEvent::Stomper
use AnyEvent; use AnyEvent::Stomper::Pool; my $pool = AnyEvent::Stomper::Pool->new( nodes => [ { host => 'stomp-server-1.com', port => 61613 }, { host => 'stomp-server-2.com', port => 61613 }, { host => 'stomp-server-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;
AnyEvent::Stomper::Pool is connection pool for AnyEvent::Stomper. This module can be used to work with cluster or set of STOMP servers.
my $stomper = AnyEvent::Stomper::Pool->new( nodes => [ { host => 'stomp-server-1.com', port => 61613 }, { host => 'stomp-server-2.com', port => 61613 }, { host => 'stomp-server-3.com', port => 61613 }, ], login => 'guest', passcode => 'guest', vhost => '/', heartbeat => [ 5000, 5000 ], connection_timeout => 5, lazy => 1, reconnect_interval => 5, on_node_connect => sub { # handling... }, on_node_disconnect => sub { # handling... }, on_node_error => sub { my $err = shift; # error handling... }, );
Specifies the list of nodes. Parameter should contain array of hashes. Each hash should contain host and port elements.
host
port
The user identifier used to authenticate against a secured STOMP server.
The password used to authenticate against a secured STOMP server.
The name of a virtual host that the client wishes to connect to.
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.
0
heartbeat => [ 5000, 5000 ],
Not set by default.
Specifies connection timeout. If the client could not connect to the node after specified timeout, the on_node_error callback is called with the E_CANT_CONN error. The timeout specifies in seconds and can contain a fractional part.
on_node_error
E_CANT_CONN
connection_timeout => 10.5,
By default the client use kernel's connection timeout.
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.
new
Disabled by default.
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,
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.
autocork
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.
on_node_connect
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.
on_node_disconnect
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 the on_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.
Gets specified node.
Gets all available nodes.
Gets random node.
Gets next node from nodes list cyclically.
The method for forced disconnection. All uncompleted operations will be aborted.
AnyEvent::Stomper
Eugene Ponizovsky, <ponizovsky@gmail.com>
Sponsored by SMS Online, <dev.opensource@sms-online.com>
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.
To install AnyEvent::Stomper, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Stomper
CPAN shell
perl -MCPAN -e shell install AnyEvent::Stomper
For more information on module installation, please visit the detailed CPAN module installation guide.