Net::Async::NATS

Async NATS messaging client for IO::Async.

Synopsis

use IO::Async::Loop;
use Net::Async::NATS;

my $loop = IO::Async::Loop->new;
my $nats = Net::Async::NATS->new(
    host => 'localhost',
    port => 4222,
);
$loop->add($nats);

await $nats->connect;

# Subscribe
my $sub = await $nats->subscribe('greet.*', sub {
    my ($subject, $payload, $reply_to) = @_;
    print "Got: $payload on $subject\n";
});

# Publish
await $nats->publish('greet.world', 'Hello!');

# Request/Reply
my ($payload) = await $nats->request('service.echo', 'ping', timeout => 5);

# Unsubscribe
await $nats->unsubscribe($sub);

# Disconnect
await $nats->disconnect;

Features

Installation

cpanm Net::Async::NATS

Or from source:

cpanm --installdeps .
dzil install

Testing

Unit tests (no NATS server required):

prove -l t/

Live integration tests (requires a running NATS server):

TEST_NATS_HOST=localhost prove -lv t/03-live.t

See Also

Author

Torsten Raudssus torsten@raudssus.de

License

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.