nats
Last updated
Was this helpful?
Last updated
Was this helpful?
A command line utility to interact with and manage NATS.
This utility replaces various past tools that were named in the form nats-sub
and nats-pub
, adds several new capabilities and supports full JetStream management.
Check out the repo for all the details: .
nats
Please refer to the .
You can read about execution policies .
Binaries are also available as .
nats
nats help
nats help [<command>...]
or nats [<command>...] --help
Remember to look at the cheat sheets!
nats cheat
nats cheat --sections
nats cheat <section>>
nats context
nats account
nats pub
nats sub
nats request
nats reply
nats bench
nats events
nats rtt
nats server
nats latency
nats governor
nats stream
nats consumer
nats backup
nats restore
nats kv
nats errors
nats schema
The CLI has a number of configuration settings that can be passed either as command line arguments or set in environment variables.
Output extract
A context is a named configuration that stores all of these settings. You can designate a default context and switch between contexts.
A context can be created with nats context create my_context_name
and then modified withnats context edit my_context_name
:
This context is stored in the file ~/.config/nats/context/my_context_name.json
.
A context can also be created by specifying settings with nats context save
List your contexts
We passed --select
to the local
one meaning it will be the default when nothing is set.
Select a context
Check the round trip time to the server (using the currently selected context)
You can also specify a context directly
All nats
commands are context aware and the nats context
command has various commands to view, edit and remove contexts.
Server URLs and Credential paths can be resolved via the nsc
command by specifying an URL, for example to find user new
within the orders
account of the acme
operator you can use this:
The server list and credentials path will now be resolved via nsc
, if these are specifically set in the context, the specific context configuration will take precedence.
The nats
utility has a command for creating bcrypt
hashes. This can be used for a password or a token in the configuration.
To use the password on the server, add the hash into the server configuration file's authorization section.
Note the client will still have to provide the plain text version of the password, the server however will only store the hash to verify that the password is correct when supplied.
Publish-subscribe pattern using the NATS CLI
The server URL can be set using the --server
CLI flag, or the NATS_URL
environment variable, or using .
The password can be set using the --password
CLI flag, or the NATS_PASSWORD
environment variable, or using . For example: if you want to create a script that prompts the user for the system user password (so that for example it doesn't appear in ps
or history
or maybe you don't want it stored in the profile) and then execute one or more nats
commands you do something like:
The server supports hashing of passwords and authentication tokens using bcrypt
. To take advantage of this, simply replace the plaintext password in the configuration with its bcrypt
hash, and the server will automatically utilize bcrypt
as needed. See also: .