POEx::ZMQ3::Subscriber - A SUB-type ZeroMQ socket
use POE; my $zsub = POEx::ZMQ3::Subscriber->new(); POE::Session->create( inline_states => { _start => sub { ## Connect to a ZeroMQ publisher: $zsub->start( 'tcp://127.0.0.1:5665' ); ## Our session wants all emitted events: $_[KERNEL]->post( $zsub->session_id, 'subscribe', 'all' ); }, zeromq_subscribed_to => { my $target = $_[ARG0]; print "Subscribed to $target\n"; }, zeromq_received => { my $data = $_[ARG0]; print "Received $data from publisher\n"; if (++$_[HEAP]->{count} == 1000) { warn "I don't want any more messages :("; $zsub->stop; } }, }, ); $poe_kernel->run;
A lightweight ZeroMQ subscriber-type socket using POEx::ZMQ3::Role::Emitter.
This is a simple subscriber; by default it indiscriminately receives all published messages without filtering.
$zsub->start( $subscribe_to );
Start the Subscriber and connect to a specified target.
$zsub->stop;
Stop the Subscriber, closing out the socket and stopping the event emitter.
Emitted when we are initialized; $_[ARG0] is the target publisher's address.
Emitted when we receive data from the publisher we are subscribed to
If this is a single-part message, $_[ARG0] is the (raw) data received.
If this is a multi-part message, slurp the argument array to receive all parts:
sub zeromq_received { my @parts = @_[ARG0 .. $#_]; my $envelope = shift @parts; . . . }
POEx::ZMQ3
POEx::ZMQ3::Publisher
ZMQ::LibZMQ3
http://www.zeromq.org
Jon Portnoy <avenj@cobaltirc.org>
To install POEx::ZMQ3, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POEx::ZMQ3
CPAN shell
perl -MCPAN -e shell install POEx::ZMQ3
For more information on module installation, please visit the detailed CPAN module installation guide.