NAME
ZeroMQ::PubSub::Client - Connect to a PubSub server to send and receive events
SYNOPSIS
use ZeroMQ::PubSub::Client;
use Time::HiRes;
my $client = ZeroMQ::PubSub::Client->new(
publish_address => 'tcp://127.0.0.1:4000',
subscribe_address => 'tcp://127.0.0.1:5000',
debug => 1,
);
my $ping_start_time;
# called when we receive our ping back
$client->subscribe(ping => sub {
# print round-trip latency
my ($self, $params) = @_;
print "Ping: " . (Time::HiRes::time() - $ping_start_time) . "s.\n";
});
# publish ping event
$ping_start_time = Time::HiRes::time();
$client->publish( ping => { 'time' => $ping_time } );
# wait to receive our ping
$client->poll_once;
ATTRIBUTES
publish_address
Address of event publishing socket. Must be in the form of transport://addr
. See https://metacpan.org/module/ZeroMQ::Socket#bind
subscribe_address
Address of socket to receive events from. See above.
METHODS
connect_subscribe_sock
Connects to the subscription socket on the server. Automatically called by subscribe()
and poll_once()
.
connect_publish_sock
Connects to the subscription socket on the server. Automatically called by subscribe()
and poll_once()
.
poll_once
Blocks and waits for an event. Dispatches to event callbacks.
publish($event, $params)
Publishes $event to all subscribers on the server. This will block while attempting to connect.