Just a playground for NATS things. This is just for experimentations and figuring things out, and shouldn't be used in production or as a guide to do anything useful.
This repository uses forego, however, the commands can be found in the Procfile.
Nats CLI: 0.0.33 Nats Server: 2.8.4
This repo contains a subfolder nsc
that contains the entire keystore for the clusters, Intentionally the keys are stored in here without the .gitignore
for purposes of the demo, don't do this!!!!
To interact with nsc
, you will need to setup some environment values:
export NSC_NO_GIT_IGNORE=true
export NKEYS_PATH=./nsc/keys
export NSC_HOME=./nsc/config
nsc env -s ./nsc/store
Use nsc describe account
to verify it is working and displays information about the APP
account.
To generate a new set of keys:
./bin/generate-accounts.sh
Then need to update the ./conf/leaf-remotes.conf with the correct account NKey Public keys for SYS and APP accounts. These can be found using nsc describe account --name=<name>
and use the Account ID
value.
This will startup a standalone jetstream enabled NATS server
nats-server --config ./conf/standalone.conf
After the server is up, you need to run the nsc push -A -u nats://localhost:4222
command. This will push the accounts and users to the nats server.
This will startup a NATS Cluster (hub
) with Jetstream running, and a Leaf Node (spoke
) with Jetstream running connected to the hub
This repo contains a super basic version of an account server, on startup it will read from the nsc/store
for accounts and pre-load them. It will respond to Nats SYS Claim request, as well as update the claims from an nsc push
. Don't use this in production please, its a prototype.
go run ./cmd/accountsrv/.
nats-server --config ./conf/hub.1.conf
nats-server --config ./conf/hub.2.conf
nats-server --config ./conf/hub.3.conf
nats-server --config ./conf/spoke.1.conf
nats-server --config ./conf/spoke.2.conf
nats-server --config ./conf/spoke.3.conf
When the server starts for the first time, you will encounter some errors in the logs about not being able to lookup the account for one of the leaf node connections. This is ok. As soon as the SYS
leaf node connection is established, the APP
account can be resolved from the account server connected to the hub. It might be somewhat ideal to have an account server connected to each cluster to prevent this issue.
nats context save --server nats://localhost:4222 --creds ./nsc/keys/creds/local/APP/pubsub.creds local-app
nats context save --server nats://localhost:4222 --creds ./nsc/keys/creds/local/SYS/sys.creds local-sys
nats context select local-sys
nats server ls
nats context select local-app
nats --js-domain hub stream add --config ./data/orders.json
nats --js-domain spoke stream add --config ./data/orders.json
nats consumer add ORDERS TEST --target="orders.received" --ack explicit --deliver all --max-deliver=-1 --sample 100 --replay=instant --filter="" --max-pending=0 --no-headers-only --backoff=none --deliver-group="" --heartbeat=-1 --no-flow-control
nats pub order.1 "order 1"
go run ./cmd/jssub/.