$ command-helper

NATS (nats CLI)

Publish and subscribe, request-reply, JetStream streams and consumers, key-value store and server checks.

Requires Google sign-in

Core NATS

Save connection settings as a context
nats context save <nats_context> --server nats://<host>:4222 --select
Subscribe to a subject (wildcards allowed)
nats sub "<subject>.>"
Publish a message
nats pub <subject> "hello"
Request-reply
nats request <subject> "ping" --timeout 2s
Measure round-trip time to the server
nats rtt
Quick throughput benchmarkadvanced
nats bench <subject> --pub 2 --sub 2 --msgs 100000

JetStream

List streams
nats stream ls
Create a stream (interactive)
nats stream add <stream> --subjects "<subject>.>"
Stream info: messages, bytes, consumers
nats stream info <stream>
Read a message by sequence
nats stream get <stream> 1
Consumers of a stream and their lag
nats consumer report <stream>
Purge a streamadvanced
nats stream purge <stream>
Back up a stream to a directoryadvanced
nats stream backup <stream> ./backup

Key-value store

Create a bucket
nats kv add <kv_bucket>
Put and get a key
nats kv put <kv_bucket> <kv_key> "value" && nats kv get <kv_bucket> <kv_key>
Watch a bucket for changes
nats kv watch <kv_bucket>

Server

Server health check
nats server check connection --server nats://<host>:4222
Monitoring endpoint: connectionsadvanced
curl -s http://<host>:8222/connz | jq '.num_connections'