Configuration
The NATS configuration file supports the following syntax:
- Lines can be commented with and
//
- Values can be assigned to properties with:
- Equals sign:
foo = 2
- Colon:
foo: 2
- Whitespace:
foo 2
- Equals sign:
- Arrays are enclosed in brackets:
["a", "b", "c"]
- Maps are enclosed in braces:
{foo: 2}
- Maps can be assigned with no key separator
- Semicolons can be used as terminators
The NATS configuration file is parsed with UTF-8 encoding.
The configuration parser is very forgiving, as you have seen:
- values can be a primitive, or a list, or a map
- strings and numbers typically do the right thing
- numbers support units such as, 1K for 1000, 1KB for 1024
String values that start with a digit can create issues. To force such values as strings, quote them.
BAD Config:
authorization: {
token: "3secret"
}
Server configurations can specify variables. Variables allow you to reference a value from one or more sections in the configuration.
Variables:
- Are block-scoped
- Are referenced with a
$
prefix. - Can be resolved from environment variables having the same name
A similar configuration, but this time, the value is in the environment:
# TOKEN is defined in the environment
authorization {
token: $TOKEN
}
export TOKEN=”hello”; nats-server -c /config/file
Includes must use relative paths, and are relative to the main configuration (the one specified via the -c
option):
server.conf:
Note that
include
is not followed by=
or:
, as it is a directive.
auth.conf:
authorization: {
token: "f0oBar"
Connection Timeouts
Property | Description | Default |
---|---|---|
ping_interval |
Duration at which pings are sent to clients, leaf nodes and routes. In the presence of client traffic, such as messages or client side pings, the server will not send pings. Therefore it is recommended to keep this value bigger than what . | "2m" |
ping_max |
After how many unanswered pings the server will allow before closing the connection. | 2 |
write_deadline |
Maximum number of seconds the server will block when writing. Once this threshold is exceeded the connection will be closed. See slow consumer on how to deal with this on the client. | "2s" |
Authentication and Authorization
Centralized Authentication and Authorization
Property | Description |
---|---|
Configuration map for client authentication/authorization. | |
accounts |
Configuration map for multi tenancy via accounts. |
Username present in the or an account . A client connecting without any form of authentication will be associated with this user, its permissions and account. |
Decentralized Authentication and Authorization
The Configuration options here refer to JWT based authentication and authorization.
Property | Description | Default |
---|---|---|
disable_sublist_cache |
If true disable subscription caches for all accounts. This is saves resources in situations where different subjects are used all the time. |
, cache enabled |
lame_duck_duration |
In lame duck mode the server rejects new clients and slowly closes client connections. After this duration is over the server shuts down. Start lame duck mode with: . | "2m" |
Monitoring and Tracing
> nats-server --signal reload