Created
October 3, 2012 00:28
-
-
Save semifor/3824196 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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