In the world of NoSQL

Example code to create a simple push/pull based ventilator and sink in Perl with ZMQ::LibZMQ3 bindings.

Ventilator code:

#!/usr/bin/perl -w
 
$|++;
 
use ZMQ::LibZMQ3;
use ZMQ::Constants qw/ZMQ_PUSH/;
 
my $context = zmq_init(1);
my $socket = zmq_socket($context, ZMQ_PUSH);
zmq_bind($socket, "tcp://*:2222");
 
while (1) {
  print "Sent one\n";
  zmq_sendmsg($socket, zmq_msg_init_data("Woop"));
}

Sink code:

#!/usr/bin/perl -w
 
$|++;
 
use ZMQ::LibZMQ3;
use ZMQ::Constants qw/ZMQ_PULL/;
 
my $context = zmq_init(1);
my $socket = zmq_socket($context, ZMQ_PULL);
zmq_connect($socket, "tcp://localhost:2222");
 
while (1) {
  my $msg = zmq_recvmsg($socket);
  my $data = zmq_msg_data($msg);
  print scalar(localtime).": received message: $data\n";
}

Read more...

§198 · januari 16, 2013 · Message Queues, ZeroMQ · Kommentarer inaktiverade för ZeroMQ p5-ZMQ (ZMQ::LibZMQ3) sink/ventilator example (push/pull) · Tags: , , , , ,


First of all, install some dependencies:

# apt-get install libmodule-build-perl libb-hooks-op-annotation-perl libtest-requires-perl  libtest-tcp-perl libtask-weaken-perl libtool automake autoconf build-essential libmodule-install-perl

Download and install zeromq:

# wget -qO - http://download.zeromq.org/zeromq-3.2.2.tar.gz|tar -zxv
# cd zeromq-3.2.2
# ./autogen.sh
# ./configure
# make
# make install

Download p5-ZMQ:

# git clone git://github.com/lestrrat/p5-ZMQ.git

Then install ZMQ::Constants:

# cd p5-ZMQ/ZMQ-Constants
# perl Makefile.PL
# make
# make install

Continue with ZMQ::LibZMQ3, you need a newer version of Module::Install::XSUtil than Debian ships with, together with Module::Install::AuthorTests that’s not availalbe as a Debian package:

# cd ../ZMQ-LibZMQ3
# apt-get remove libmodule-install-xsutil-perl
# perl -MCPAN -e 'install Module::Install::XSUtil'
# perl -MCPAN -e 'install Module::Install::AuthorTests'
# perl -MCPAN -e 'install Module::Install::CheckLib'
# perl -MCPAN -e 'install Devel::CheckLib'
# perl Makefile.PL
# make
# make install

Problems

root@server:~/p5-ZMQ/ZMQ-LibZMQ3# perl Makefile.PL
include /root/p5-ZMQ/ZMQ-LibZMQ3/inc/Module/Install.pm
Variable "@libs" is not imported at Makefile.PL line 66.
	(Did you mean &libs instead?)
syntax error at Makefile.PL line 63, near "assertlibs
        lib"
Global symbol "@libs" requires explicit package name at Makefile.PL line 66.
Execution of Makefile.PL aborted due to compilation errors.

This happens if you don’t have Module::Install::CheckLib installed.

If you don’t want to install Module::Install::CheckLib it also works by removing that part of the Makefile.PL by running:

# sed -i -re '60,68s/^/#/' Makefile.PL

After that it worked.

Read more...