Synchronized subscriber in Perl


Synchronized subscriber

Author: Alexander D'Archangel (darksuji) <darksuji(at)gmail(dot)com>


use strict;
use warnings;
use 5.10.0;

use ZeroMQ qw/:all/;

my $context = ZeroMQ::Context->new();

# First, connect our subscriber socket
my $subscriber = $context->socket(ZMQ_SUB);
$subscriber->setsockopt(ZMQ_SUBSCRIBE, '');

# 0MQ is so fast, we need to wait a while…
sleep (1);

# Second, synchronize with publisher
my $syncclient = $context->socket(ZMQ_REQ);

# - send a synchronization request

# - wait for synchronization reply

# Third, get our updates and report how many we got
my $update_nbr = 0;
while (1) {
my $string = $subscriber->recv()->data;
last if $string eq 'END';
say "Received $update_nbr updates";