LinuxCommandLibrary

nats

CLI for NATS messaging system

TLDR

Publish a message

$ nats pub [subject] "[message]"
copy
Subscribe to subject
$ nats sub [subject]
copy
Request/reply
$ nats req [subject] "[request]"
copy
Reply to requests
$ nats reply [subject] "[response]"
copy
List streams (JetStream)
$ nats stream ls
copy
Create a stream
$ nats stream add [stream-name]
copy
Publish to stream
$ nats pub [subject] "[message]"
copy
View server info
$ nats server info
copy

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

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community