Minimal synchronous NATS Zig client.
Features:
- subject subscription
- message publishing
- tls connections
- nkey authentication
- connecting to the ngs
- non allocating protocol parser
Build project:
git clone --recurse-submodules [email protected]:ianic/nats.zig.git
cd nats.zig
zig build
Tested only using latest master 0.10-dev release.
You should have installed nats-server. Start it locally:
nats-server
Start subscriber in one terminal:
./zig-out/bin/sub
and publisher to send few messages to the foo
subject on which subscriber is listening:
./zig-out/bin/pub
To connect and publish/subscribe to the ngs network you need valid credentials file. Start the ngs example and point it to the credentials file and specify a subject name. Example will both subscribe and publish few messages.
./zig-out/bin/ngs credentials_file.creds subject
Project depends on libressl for handling tls connections. Can be built using libressl from project or system.
To install libressl on macos:
brew install libressl
and on linux:
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.6.0.tar.gz
tar -xf libressl-3.6.0.tar.gz
ls -al
cd libressl-3.6.0/
./configure
sudo make install
After that project can be build using system libressl:
zig build -Duse-system-libressl
- zig-libressl
- nats protocol documentation (that page is referencing also Derek's talk about zero allocation parser)
- zig-nats and zig-nkeys by Rutger Broekhoff
- Twitter conversLation