[zeromq-dev] ZMQx::Class - a more Perlish interface to ZeroMQ

Thomas Klausner domm at cpan.org
Mon Oct 7 09:23:06 CEST 2013


Hi!

Sort of in reaction to Dylan Calis post about ZMQ::FFI I'm finally 
announcing our high-level ZeroMQ Perl wrapper:

https://metacpan.org/module/ZMQx::Class
https://github.com/domm/ZMQx-Class

It's using ZMQ::LibZMQ3 and Moose, key features are:
* Easy setup of sockets
* Easy setting & getting of sockopts
* Easy sending & receiving of single- and multipart messages
* Fork / Context handling
* AnyEvent helpers


Here's an example publisher:

use ZMQx::Class;
use Time::HiRes qw(usleep);

my $publisher = ZMQx::Class->socket( 'PUB', bind => 'tcp://*:10000' );

while ( 1 ) {
    my $random = int( rand ( 10_000 ) );
    say "sending $random hello";
    $publisher->send( [ $random, 'hello' ] );
    usleep(1000);
}


and here a matching subscriber:


use ZMQx::Class;
use Anyevent;
 
my $subscriber = ZMQx::Class->socket( 'SUB', connect => 'tcp://localhost:10000' );
$subscriber->subscribe( '1' );
 
my $watcher = $subscriber->anyevent_watcher( sub {
    while ( my $msg = $subscriber->receive ) {
        say "got $msg->[0] saying $msg->[1]";
    }
});
AnyEvent->condvar->recv;


Any Feedback is welcome!

Greetings,
domm


-- 
#!/usr/bin/perl                              http://domm.plix.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}



More information about the zeromq-dev mailing list