NAME

POEx::ZMQ3::Subscriber - A SUB-type ZeroMQ socket

SYNOPSIS

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;

DESCRIPTION

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.

Methods

start

$zsub->start( $subscribe_to );

Start the Subscriber and connect to a specified target.

stop

$zsub->stop;

Stop the Subscriber, closing out the socket and stopping the event emitter.

Events

zeromq_subscribed_to

Emitted when we are initialized; $_[ARG0] is the target publisher's address.

zeromq_received

Emitted when we receive data from the publisher we are subscribed to; $_[ARG0] is the (raw) data received. (No special handling of multipart messages currently takes place.)

SEE ALSO

POEx::ZMQ3

POEx::ZMQ3::Publisher

ZMQ::LibZMQ3

http://www.zeromq.org

AUTHOR

Jon Portnoy <avenj@cobaltirc.org>