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";
}
§198 · januari 16, 2013 · Message Queues, ZeroMQ · Tags: , , , , , · [Print]

Comments are closed.