SynapSteward with NATS

NATS with JetStream for SynapSteward communication

Decided on NATS with JetStream for SynapSteward communication. NATS is a lightweight messaging system that is easy to use and deploy. JetStream is a streaming platform built on top of NATS that provides persistence and replay capabilities.

Deployment

All my devices are hooked up to a private TailScale network. So, I don’t really worry about authentication and encryption of the NATS connection. I just need to make sure that the NATS server is running on a machine that is available all the time. Could have hooked up a Raspberry Pi to do this, but chose the lazy way out and used a cheap Hetzner Cloud server instead.

 1$ cat >nats.conf <<EOF
 2jetstream {
 3    store_dir: /data
 4    max_mem: 512M
 5    max_file: 1G
 6}
 7EOF
 8
 9$ cat >compose.yaml <<EOF
10# Docker compose for a NATS JetStream server
11
12services:
13  nats:
14    image: nats:2.10-alpine
15    ports:
16      - "4222:4222"
17    command: [ "nats-server", "--js", "-p", "4222", "--config", "/etc/nats/nats.conf" ]
18    restart: unless-stopped
19    networks:
20      - nats
21    volumes:
22      - data:/data
23      - ./nats.conf:/etc/nats/nats.conf:ro
24
25networks:
26  nats: {}
27
28volumes:
29  data: {}
30EOF
31
32$ docker compose up -d

Clients

Installed the NATS client, natscli on my laptop using Nix and home-manager.

And then configured a default context for the NATS server.

1$ nats context add cloudhaus --description cloudhaus --server nats://cloudhaus:4222
2$ nats account info

Now, need to decide on the schema for the streams and subjects that SynapSteward will use.

#synapsteward   #nats