The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

POEx::ZMQ3::Requestor

SYNOPSIS

  use POE;

  my $zreq = POEx::ZMQ3::Requestor->new();

  POE::Session->create(
    inline_states => {

      _start => sub {
        ## Connect to a ZeroMQ REP replier:
        $zreq->start( 'tcp://127.0.0.1:5665' );
        ## Subscribe to all emitted events:
        $_[KERNEL]->post( $zreq->session_id,
          'subscribe',
          'all'
        );
      },

      zeromq_connected_to => sub {
        ## Fire off a REQ to get started.
        $zreq->request('ping!')
      },

      zeromq_got_reply => sub {
        ## Got a reply from server.
        my $data = $_[ARG0];

        if ($data eq 'pong!') {
          $zreq->request('ping!')
        } else {
          warn "Don't know what to do with $data";
          $zreq->stop;
        }
      },

    },
  );

  $poe_kernel->run;

DESCRIPTION

A ZeroMQ REQ-type socket using POEx::ZMQ3::Role::Emitter.

ZeroMQ REQ and REP (Requestors and Repliers) work synchronously; a REQ is expected to start the conversation and one request should generate one reply.

Methods

start

  $zreq->start( $rep_server );

Start the Requestor and connect to a specified REP endpoint.

stop

  $zreq->stop;

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

request

  $zreq->request( $data );

Send a request to the remote end.

Events

zeromq_connected_to

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

zeromq_got_reply

Emitted when we receive a reply to a request; $_[ARG0] is the raw data.

Attributes

targets

An ARRAY of endpoints the Requestor was configured with; see "start".

SEE ALSO

POEx::ZMQ3

POEx::ZMQ3::Replier

ZMQ::LibZMQ3

http://www.zeromq.org

AUTHOR

Jon Portnoy <avenj@cobaltirc.org>