Jon Portnoy > POEx-ZMQ3-0.03 > POEx::ZMQ3::Replier

Download:
POEx-ZMQ3-0.03.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Source   Latest Release: POEx-ZMQ3-0.071

NAME ^

POEx::ZMQ3::Replier - A REP-type ZeroMQ socket

SYNOPSIS ^

  use POE;

  my $zrep = POEx::ZMQ3::Replier->new;

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

      _start => sub {
        ## Wait for requests on an endpoint:
        $zrep->start( 'tcp://127.0.0.1:5665' );
        ## Subscribe to all emitted events:
        $_[KERNEL]->post( $zrep->session_id,
          'subscribe',
          'all',
        );
      },

      zeromq_replying_on => sub {
        my $endpoint = $_[ARG0];
        print "Waiting for requests on $endpoint\n";
      },

      zeromq_got_request => sub {
        my $data = $_[ARG0];
        ## Got a request we can reply to.
        $zrep->reply("pong!")
      },

    }
  );

  $poe_kernel->run;

DESCRIPTION ^

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

A REP-type socket waits for a request (see POEx::ZMQ3::Requestor) and issues a reply accordingly.

Methods

start

  $zrep->start( $endpoint );

Start the Replier and listen on a specified endpoint.

stop

  $zrep->stop;

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

reply

  $zrep->reply( $data );

Issue a reply to a request.

Should be called out of a "zeromq_got_request" handler.

Events

zeromq_replying_on

Emitted when we add a bound endpoint; $_[ARG0] is the endpoint we are waiting for requests on.

zeromq_got_request

Emitted when a request arrives; $_[ARG0] is the raw data.

SEE ALSO ^

POEx::ZMQ3

POEx::ZMQ3::Requestor

ZMQ::LibZMQ3

http://www.zeromq.org

AUTHOR ^

Jon Portnoy <avenj@cobaltirc.org>

syntax highlighting: