NAME
Net::NATS::Client - A Perl client for the NATS messaging system.
SYNOPSIS
#
# Basic Usage
#
$client = Net::NATS::Client->new(uri => 'nats://localhost:4222');
$client->connect() or die $!;
# Simple Publisher
$client->publish('foo', 'Hello, World!');
# Simple Async Subscriber
$subscription = $client->subscribe('foo', sub {
my ($message) = @_;
printf("Received a message: %s\n", $message->data);
});
# Process one message from the server. Could be a PING message.
# Must call at least one per ping-timout (default is 120s).
$client->wait_for_op();
# Process pending operations, with a timeout (in seconds).
# A timeout of 0 is polling.
$client->wait_for_op(3.14);
# Unsubscribe
$subscription->unsubscribe();
# Close connection
$client->close();
#
# Request/Reply
#
# Setup reply
$client->subscribe("foo", sub {
my ($request) = @_;
printf("Received request: %s\n", $request->data);
$client->publish($request->reply_to, "Hello, Human!");
});
# Send request
$client->request('foo', 'Hello, World!', sub {
my ($reply) = @_;
printf("Received reply: %s\n", $reply->data);
});
#
# TLS
#
# Set the socket arguments that will be passed to IO::Socket::SSL
my $socket_args = {
SSL_cert_file => $cert_file,
SSL_key_file => $key_file,
};
my $client = Net::NATS::Client->new(uri => 'nats://localhost:4222', socket_args => $socket_args);
$client->connect() or die $!;
REPOSITORY
https://github.com/carwynmoore/perl-nats
AUTHOR
Carwyn Moore
Vick Khera, <vivek at khera.org>
COPYRIGHT AND LICENSE
MIT License. See LICENCE for the complete licensing terms.
Copyright (C) 2016 Carwyn Moore