nats.erl

A simple NATS client library for Erlang/OTP.

CI status

This project is still WIP. Any of the implementations, including exported APIs, may change drastically and frequently.

Features

Usage

See Subscriber/Publisher examples for details.

%% Start gen_server with network info.
nats:start_link(#{remote_address => Host,
remote_port => P,
ping_interval => 1000}),
%% Connect to your NATS server.
{ok, Info} = nats:connect(),
%% Subscribe or publish with required parameters.
ok = nats:subscribe(Subject, SID),
ok = nats:publish(Subject, Message),
%% After subscribing, received messages are sent to your Pid.
receive
Msg ->
io:format("Received: ~p~n", [Msg]),
end

Running examples

Compile and run the sample subscriber.

rebar3 compile
./example/subscribe.escript 127.0.0.2 4222 foo.bar 11

Then run the sample publisher on another terminal session.

./example/publish.escript 127.0.0.2 4222 foo.bar "msg to publish"

Author(s)

Yoshiyuki Kurauchi (Website / Twitter)

We're always open to welcome co-authors! Please feel free to talk to us.

LICENSE

Apache License 2.0