Jon Portnoy > POEx-ZMQ3 > POEx::ZMQ3::Requestor

Download:
POEx-ZMQ3-0.060003.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.060003   Source  

NAME ^

POEx::ZMQ3::Requestor - A REQ-type ZeroMQ socket

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.

SEE ALSO ^

POEx::ZMQ3

POEx::ZMQ3::Replier

ZMQ::LibZMQ3

http://www.zeromq.org

AUTHOR ^

Jon Portnoy <avenj@cobaltirc.org>

syntax highlighting: