Skip to content

@semifor /ae-listener.pl
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/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 ) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.