POEx::ZMQ3::Sockets
## A 'REQ' client that sends 'PING' to a REP on localhost:5050 use strictures 1; use POE; use POEx::ZMQ3::Sockets; POE::Session->create( package_states => [ main => [ qw/ _start zmqsock_registered zmqsock_recv / ], ] ); sub _start { my ($kern, $heap) = @_[KERNEL, HEAP]; my $zmq = POEx::ZMQ3::Sockets->new; $zmq->start; $heap->{zmq} = $zmq; $kern->call( $zmq->session_id, 'subscribe', 'all' ); } sub zmqsock_registered { my ($kern, $heap) = @_[KERNEL, HEAP]; my $zmq = $heap->{zmq}; $zmq->create( 'pinger', 'REQ' ); $zmq->connect( 'pinger', 'tcp://127.0.0.1:5050' ); $zmq->write( 'pinger', 'PING' ); } sub zmqsock_recv { my ($kern, $heap) = @_[KERNEL, HEAP]; my ($alias, $data) = @_[ARG0 .. $#_]; if ($data eq 'PONG') { ## Got a PONG. Send another PING: $heap->{zmq}->write( 'pinger', 'PING' ); } } $poe_kernel->run;
This software is deprecated and known-broken; see POEx::ZMQ instead!
This is the backend MooX::Role::POE::Emitter session behind POEx::ZMQ3, integrating ZeroMQ (http://www.zeromq.org) with a POE event loop.
Your POE::Session should register with the component to receive events:
## Inside a POE::Session ## Get all events from component in $_[HEAP]->{zmq}: sub my_start { my $zmq = $_[HEAP]->{zmq}; $_[KERNEL]->call( $zmq->session_id, 'subscribe', 'all' ); }
See "POE API" for more on events emitted and accepted by this component.
See MooX::Role::POE::Emitter for more details on event emitters; the documentation regarding event prefixes and session details lives there.
Takes no arguments.
Spawns the MooX::Role::POE::Emitter session that controls ZMQ socket handling. Must be called prior to operating on sockets.
Stops the component, closing out all active sockets.
Takes a socket alias and a socket type.
Creates a new ZeroMQ socket. The socket is not initially bound/connected to anything; see "bind", "connect".
The socket type may be either a constant from ZMQ::Constants or a string type:
## Equivalent: $zmq->create( $alias, 'PUB' ); use ZMQ::Constants 'ZMQ_PUB'; $zmq->create( $alias, ZMQ_PUB );
See the zmq_socket man page for details.
Takes a socket alias and an endpoint to listen for connections on.
The opposite of "bind" is "connect"
Takes a socket alias and a target endpoint to connect to.
Note that ZeroMQ manages its own connections asynchronously. A successful "bind" or "connect" is not necessarily indicative of a positively usable connection.
Takes a socket alias, some data (as a scalar), and optional flags to pass to ZeroMQ's zmq_msg_send:
## Write a simple message: $zmq->write( $alias, 'A message' ); ## Write some serialized data: my $ref = { things => 'some data' }; my $data = Storable::nfreeze( $ref ); $zmq->write( $alias, $data );
Writes data to the ZMQ socket, when possible.
Also see "write_multipart".
Takes a socket alias and a list of scalar data items to send as a multi-part message:
$zmq->write_multipart( $alias, $header, $content );
See the ZeroMQ documentation for details regarding multi-part messages.
Also see "zmqsock_multipart_recv"
Takes a socket alias.
Closes the specified ZMQ socket.
Returns the current POEx::ZMQ3::Context object.
Returns the actual ZMQ::LibZMQ3 socket object.
Takes a socket alias and arbitrary flags/options to pass to zmq_setsockopt.
See the man page for zmq_setsockopt.
Takes a socket alias and an optional subscription prefix.
Calls "set_zmq_sockopt" to set the ZMQ_SUBSCRIBE flag for the specified socket; this is used by SUB-type sockets to subscribe to messages.
ZMQ_SUBSCRIBE
If no subscription prefix is specified, the socket will be subscribed to all messages.
Emitted when a "bind" has been executed.
$_[ARG0] is the socket's alias.
$_[ARG1] is the endpoint string.
Emitted when a "connect" has been executed.
Emitted when some data has been received on a socket.
$_[ARG1] is the raw message data extracted via zmq_msg_data.
Emitted when multipart data has been received on a socket.
$_[ARG1] is an ARRAY containing the raw data extracted from each message part.
Emitted when a socket has been created.
$_[ARG0] is the alias that was spawned.
$_[ARG1] is the socket's type, as a ZMQ::Constants constant.
Emitted when a socket is being shut down.
$_[ARG0] is the alias that is closing.
The following events take the same parameters as their counterparts described in "Methods":
create
close
bind
connect
write
write_multipart
POEx::ZMQ3
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.