public
Created

  • Download Gist
ae-listener.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/env perl
use 5.12.1;
use warnings;
use strict;
 
use ZeroMQ qw/:all/;
use ZeroMQ::Raw qw/zmq_device/;
 
my $worker_address = 'ipc:///tmp/workers.sock';
 
# Workers
for ( 0 .. 4 ) {
fork || do {
my $ctxt = ZeroMQ::Context->new;
my $parent = $ctxt->socket(ZMQ_PULL);
$parent->bind($worker_address);
while ( my $msg = $parent->recv ) {
say "Worker $$:" . $msg->data;
}
};
}
 
# TEST CLIENT
# This routine isn't actually part of this client, it's here simply for example purposes
# it replicates various clients that will be talking to the services
fork || do {
my $ctxt = ZeroMQ::Context->new;
my $server = $ctxt->socket(ZMQ_PUSH);
$server->connect($worker_address);
 
for my $i ( 1 .. 50 ) {
say "Client $$: $i";
$server->send_as( json => { client => $$, pid => $i } );
}
};
 
while ( wait != -1 ) {}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.