I need to write a server program that will open and keep 5 live Telnet, SSH and various connections to a server, while it listens to JSONRPC calls on the other side.
I’ve no problem with opening and maintaining the 5 connections, and listening for requests:
# workers:
open_myconnections( 1..5 );
my $w1 = AnyEvent->timer (interval => $seconds, cb => sub { keep_conn_alive(1) });
my $w2 = AnyEvent->timer (interval => $seconds, cb => sub { keep_conn_alive(2) });
...
# now listen for requests
use AnyEvent::JSONRPC::Lite;
# master:
my $server = jsonrpc_server '127.0.0.1', '4423';
$server->reg_cb(
queue_up => sub {
my ($res_cv, @params) = @_;
my $res = send_params_to_connection_queue( @params );
$res_cv->result($res);
},
);
But now I’m stuck trying to figure out the best way (ie the non-blocking, AnyEvent way) to distribute the queue among the 5 workers, which is what my function send_params_to_connection_queue() does.
Any module suggestion is appreciated, although I’m trying to avoid using POE since this is supposed to be a very tiny server and, unless no other sensible option exists, I’ll pass.
At YAPC::NA 2011 I learned about a very nice queueing system called ZeroMQ. With Perl Bindings at Direct Perl Bindings and AnyEvent bindings.
|----- ssh worker JSONRPC-Listener-EventLoop---->QueueingSystem---|----- telnet worker |----- etc.