Net::Async::ZMQ - IO::Async support for ZeroMQ
version 0.002
use IO::Async::Loop; use Net::Async::ZMQ; use Net::Async::ZMQ::Socket; use ZMQ::LibZMQ3; # or ZMQ::LibZMQ4 use ZMQ::Constants qw( ZMQ_REQ ZMQ_NOBLOCK ZMQ_EVENTS ZMQ_POLLIN ); my $loop = IO::Async::Loop->new; my $ctx = zmq_init(); my $client_socket = zmq_socket( $ctx, ZMQ_REQ ); zmq_connect( $client_socket, "tcp://127.0.0.1:9999" ); my $counter = 0; my $zmq = Net::Async::ZMQ->new; zmq_sendmsg( $client_socket, "initial message" ); $zmq->add_child( Net::Async::ZMQ::Socket->new( socket => $client_socket, on_read_ready => sub { while ( zmq_getsockopt( $client_socket, ZMQ_EVENTS ) & ZMQ_POLLIN ) { my $recvmsg = zmq_recvmsg( $client_socket, ZMQ_NOBLOCK ); my $msg = zmq_msg_data($recvmsg); zmq_sendmsg( $client_socket, "hello @{[ $counter++ ]}" ); } }, ) ); $loop->add( $zmq ); $loop->run;
A subclass of IO::Async::Notifier that can hold ZMQ sockets that are provided by Net::Async::ZMQ::Socket.
Supports sockets from the following libraries:
ZMQ::LibZMQ3
ZMQ::LibZMQ4
ZMQ::FFI
IO::Async::Notifier
ZMQ_FD in zmq_getsockopt
ZMQ_FD
zmq_getsockopt
ZeroMQ - Edge Triggered Notification
Zakariyya Mughal <zmughal@cpan.org>
This software is copyright (c) 2017 by Zakariyya Mughal.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Net::Async::ZMQ, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::Async::ZMQ
CPAN shell
perl -MCPAN -e shell install Net::Async::ZMQ
For more information on module installation, please visit the detailed CPAN module installation guide.