nats
CLI for NATS messaging system
TLDR
Publish a message
SYNOPSIS
nats command [options] [args...]
DESCRIPTION
nats is the CLI for NATS messaging system. It provides pub/sub messaging, request/reply patterns, and JetStream persistence operations.
Core NATS offers at-most-once messaging. pub sends messages, sub receives. Subject wildcards support: \* matches single token, > matches multiple tokens.
JetStream adds persistence with streams and consumers. stream add creates durable storage; consumers track delivery. Key-value and object stores provide higher-level abstractions on JetStream.
Contexts save connection details for multiple environments. Use context add to create and context select to switch.
Request/reply enables RPC patterns. req sends and waits for response; services use reply or custom subscribers to respond.
PARAMETERS
-s, --server url
NATS server URL. Default: nats://localhost:4222.--creds file
Credentials file for authentication.--user user
Username for authentication.--password pass
Password for authentication.--nkey file
NKey file for authentication.--tlscert file
TLS client certificate.--tlskey file
TLS client key.--context name
Use named context.
COMMANDS
pub subject [message]
Publish message to subject.sub subject
Subscribe to subject.req subject [payload]
Send request and wait for reply.reply subject [response]
Reply to requests on subject.stream ls|add|info|rm|edit|purge
Manage JetStream streams.consumer ls|add|info|rm|next
Manage stream consumers.kv add|get|put|del|ls
Key-value store operations.object add|get|put|del|ls
Object store operations.server info|list|ping|report
Server information.account info
Account information.context add|select|ls|rm
Manage connection contexts.
CAVEATS
Core NATS is fire-and-forget; use JetStream for delivery guarantees. Subject naming uses dot separators. Large messages may require configuration. Contexts store credentials on disk.
HISTORY
NATS was created by Derek Collison and first released in 2010 as a Ruby gem, rewritten in Go in 2012. Originally used at Apcera, it became a CNCF incubating project in 2018 and graduated in 2023. JetStream added persistence in NATS 2.2 (2021). The system emphasizes simplicity, performance, and operational ease for cloud-native messaging.
SEE ALSO
rabbitmqctl(1), kafka-console-producer(1), mosquitto_pub(1)
