Configuration File
You can use a configuration file to configure the options specific to the NATS Streaming Server.
Use the -sc
or --stan_config
command line parameter to specify the file to use.
For the embedded NATS Server, you can use another configuration file and pass it to the Streaming Server using -c
or --config
command line parameters.
Since most options do not overlap, it is possible to combine all options into a single file and specify this file using either the -sc
or -c
command line parameter.
However, the option named tls
is common to NATS Server and NATS Streaming Server. If you plan to use a single configuration file and configure TLS, you should have all the streaming configuration included in a streaming
map. This is actually a good practice regardless if you use TLS or not, to protect against possible addition of new options in NATS Server that would conflict with the names of NATS Streaming options.
For instance, you could use a single configuration file with such content:
However, if you want to avoid any possible conflict, simply use two different configuration files.
Note the order in which options are applied during the start of a NATS Streaming server:
Start with some reasonable default options.
If a configuration file is specified, override those options
with all options defined in the file. This includes options that are defined
but have no value specified. In this case, the zero value for the type of the
option will be used.
Any command line parameter override all of the previous set options.
In general the configuration parameters are the same as the command line arguments. Below is the list of NATS Streaming parameters:
Note: You may need to scroll horizontally to see all columns.
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
cluster_id | Cluster name | String, underscore possible |
|
| All |
discover_prefix | Subject prefix for server discovery by clients | NATS Subject |
|
| All |
store | Store type |
|
|
| All |
dir | When using a file store, this is the root directory | File path |
| N/A | All |
sd | Enable debug logging |
|
|
| All |
sv | Enable trace logging |
|
|
| All |
nats_server_url | If specified, connects to an external NATS Server, otherwise starts an embedded one | NATS URL |
| N/A | All |
secure | If true, creates a TLS connection to the server but without the need to use TLS configuration (no NATS Server certificate verification) |
|
|
| All |
tls | TLS Configuration | Map: | All | ||
store_limits | Store Limits | Map: | All | ||
file_options | File Store specific options | Map: | All | ||
hb_interval | Interval at which the server sends an heartbeat to a client | Duration |
|
| v0.3.6 |
hb_timeout | How long the server waits for a heartbeat response from the client before considering it a failed heartbeat | Duration |
|
| v0.3.6 |
hb_fail_count | Count of failed heartbeats before server closes the client connection. The actual total wait is: (fail count + 1) * (hb interval + hb timeout) | Number |
|
| v0.3.6 |
ft_group | In Fault Tolerance mode, you can start a group of streaming servers with only one server being active while others are running in standby mode. This is the name of this FT group | String |
| N/A | v0.4.0 |
partitioning | If set to true, a list of channels must be defined in store_limits/channels section. This section then serves two purposes, overriding limits for a given channel or adding it to the partition |
|
|
| v0.5.0 |
sql_options | SQL Store specific options | Map: | v0.7.0 | ||
cluster | Cluster Configuration | Map: | v0.9.0 | ||
syslog_name | On Windows, when running several servers as a service, use this name for the event source | String | v0.11.0 | ||
encrypt | Specify if server should encrypt messages (only the payload) when storing them |
|
|
| v0.12.0 |
encryption_cipher | Cipher to use for encryption. Currently support AES and CHAHA (ChaChaPoly). Defaults to AES |
|
| Depends on platform | v0.12.0 |
encryption_key | Encryption key. It is recommended to specify the key through the | String |
| N/A | v0.12.0 |
credentials | Credentials file to connect to external NATS 2.0+ Server | String |
| N/A | v0.16.2 |
username | Username is used to connect to a NATS Server when authentication with multiple users is enabled | String |
| N/A | v0.19.0 |
password | Password used with above | String |
| N/A | v0.19.0 |
token | Authentication token if the NATS Server requires a token | String |
| N/A | v0.19.0 |
nkey_seed_file | Path to an NKey seed file (1) if NKey authentication is used | File Path |
| N/A | v0.19.0 |
replace_durable | Replace the existing durable subscription instead of reporting a duplicate durable error |
|
|
| v0.20.0 |
Notes:
(1) The seed file contains the NKey seed from which the Streaming server can extract the public key and the private key used to sign the nonce sent by the NATS Server when accepting connections from the Streaming server. The file is read during the connection process, the key is used to sign but then wiped from memory. The file must contain the seed file with the following format:
TLS Configuration
Note that the Streaming Server uses a connection to a NATS Server, and so the NATS Streaming TLS Configuration is in fact a client-side TLS configuration.
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
client_cert | Client key for the streaming server | File path |
| N/A | All |
client_key | Client certificate for the streaming server | File path |
| N/A | All |
client_ca | Client certificate CA for the streaming server | File path |
| N/A | All |
server_name | Expected hostname returned in the NATS Server certificate | String |
| N/A | v0.17.0 |
insecure | Skips the NATS server's certificate chain and host name verification. Should not be used in production |
|
|
| v0.17.0 |
Store Limits Configuration
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
max_channels | Maximum number of channels, 0 means unlimited | Number >= 0 |
|
| All |
max_subs | Maximum number of subscriptions per channel, 0 means unlimited | Number >= 0 |
|
| All |
max_msgs | Maximum number of messages per channel, 0 means unlimited | Number >= 0 |
|
| All |
max_bytes | Total size of messages per channel, 0 means unlimited | Number >= 0 |
| 1GB | All |
max_age | How long messages can stay in the log | Duration |
| Unlimited | All |
max_inactivity | How long without any subscription and any new message before a channel can be automatically deleted | Duration |
| Unlimited | v0.9.0 |
channels | A map of channel names with specific limits | Map: | All |
Channels
The channels
section is a map with the key being the channel name. For instance:
For a given channel, the possible parameters are:
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
max_subs | Maximum number of subscriptions per channel, 0 means unlimited | Number >= 0 |
| Inherit from global settings | All |
max_msgs | Maximum number of messages per channel, 0 means unlimited | Number >= 0 |
| Inherit from global settings | All |
max_bytes | Total size of messages per channel, 0 means unlimited | Bytes |
| Inherit from global settings | All |
max_age | How long messages can stay in the log | Duration |
| Inherit from global settings | All |
max_inactivity | How long without any subscription and any new message before a channel can be automatically deleted | Duration |
| Inherit from global settings | v0.9.0 |
File Options Configuration
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
compact | Enable/disable file compaction. Only some of the files ( |
|
|
| All |
compact_fragmentation | Compaction threshold (in percentage) | Number >= 0 |
|
| All |
compact_interval | Minimum interval between attempts to compact files | Expressed in seconds |
|
| All |
compact_min_size | Minimum size of a file before compaction can be attempted | Bytes |
|
| All |
buffer_size | Size of buffers that can be used to buffer write operations | Bytes |
|
| All |
crc | Define if CRC of records should be computed on reads |
|
|
| All |
crc_poly | You can select the CRC polynomial. Note that changing the value after records have been persisted would result in server failing to start complaining about data corruption | Number >= 0 |
|
| All |
sync_on_flush | Define if server should perform "file sync" operations during a flush |
|
|
| All |
slice_max_msgs | Define the file slice maximum number of messages. If set to 0 and a channel count limit is set, then the server will set a slice count limit automatically | Number >= 0 |
| automatic | v0.3.4 |
slice_max_bytes | Define the file slice maximum size (including the size of index file). If set to 0 and a channel size limit is set, then the server will set a slice bytes limit automatically | Bytes |
|
| v0.3.4 |
slice_max_age | Define the period of time covered by a file slice, starting at when the first message is stored. If set to 0 and a channel age limit is set, then the server will set a slice age limit automatically | Duration |
| automatic | v0.3.4 |
slice_archive_script | Define the location and name of a script to be invoked when the server discards a file slice due to limits. The script is invoked with the name of the channel, the name of data and index files. It is the responsibility of the script to then remove the unused files | File path |
| N/A | v0.3.4 |
file_descriptors_limit | Channels translate to sub-directories under the file store's root directory. Each channel needs several files to maintain the state so the need for file descriptors increase with the number of channels. This option instructs the store to limit the concurrent use of file descriptors. Note that this is a soft limit and there may be cases when the store will use more than this number. A value of 0 means no limit. Setting a limit will probably have a performance impact | Number >= 0 |
| unlimited | v0.4.0 |
parallel_recovery | When the server starts, the recovery of channels (directories) is done sequentially. However, when using SSDs, it may be worth setting this value to something higher than 1 to perform channels recovery in parallel | Number >= 1 |
|
| v0.5.0 |
read_buffer_size | Size of buffers used to read ahead from message stores. This can significantly speed up sending messages to consumers after messages have been published. Default is 2MB. Set to 0 to disable | Bytes |
|
| v0.16.0 |
auto_sync | Interval at which the store should be automatically flushed and sync'ed on disk. Default is every minute. Set to <=0 to disable | Duration |
|
| v0.16.0 |
Cluster Configuration
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
node_id | ID of the node within the cluster if there is no stored ID | String (no whitespace) |
| N/A | v0.9.0 |
bootstrap | Bootstrap the cluster if there is no existing state by electing self as leader |
|
|
| v0.9.0 |
peers | List of cluster peer node IDs to bootstrap cluster state | List of node IDs |
| N/A | v0.9.0 |
log_path | Directory to store log replication data | File path |
| N/A | v0.9.0 |
log_cache_size | Number of log entries to cache in memory to reduce disk IO | Number >= 0 |
|
| v0.9.0 |
log_snapshots | Number of log snapshots to retain | Number >= 0 |
|
| v0.9.0 |
trailing_logs | Number of log entries to leave after a snapshot and compaction | Number >= 0 |
|
| v0.9.0 |
sync | Do a file sync after every write to the replication log and message store |
|
|
| v0.9.0 |
raft_logging | Enable logging from the Raft library (disabled by default) |
|
|
| v0.9.0 |
raft_heartbeat_timeout | Specifies the time in follower state without a leader before attempting an election | Duration |
|
| v0.11.2 |
raft_election_timeout | Specifies the time in candidate state without a leader before attempting an election | Duration |
|
| v0.11.2 |
raft_lease_timeout | Specifies how long a leader waits without being able to contact a quorum of nodes before stepping down as leader | Duration |
|
| v0.11.2 |
raft_commit_timeout | Specifies the time without an Apply() operation before sending an heartbeat to ensure timely commit. Due to random staggering, may be delayed as much as 2x this value | Duration |
|
| v0.11.2 |
proceed_on_restore_failure | Allow a non leader node to proceed with restore failures, do not use unless you understand the risks! |
|
|
| v0.17.0 |
allow_add_remove_node | Enable the ability to send NATS requests to the leader to add/remove cluster nodes |
|
|
| v0.19.0 |
bolt_free_list_sync | Causes the RAFT log to synchronize the free list on write operations. Reduces performance at runtime, but makes the recovery faster |
|
|
| v0.21.0 |
bolt_free_list_map | Sets the backend freelist type to use a map instead of the default array type. Improves performance for large RAFT logs, with fragmented free list |
|
|
| v0.21.0 |
nodes_connections | Enable creation of dedicated NATS connections to communicate with other nodes |
|
|
| v0.21.0 |
SQL Options Configuration
Parameter | Meaning | Possible Values | Usage Example | Default Value | Since |
---|---|---|---|---|---|
driver | Name of the SQL driver to use |
|
| N/A | v0.7.0 |
source | How to connect to the database. This is driver specific | String |
| N/A | v0.7.0 |
no_caching | Enable/Disable caching for messages and subscriptions operations. |
|
|
| v0.7.0 |
max_open_conns | Maximum number of opened connections to the database. Value <= 0 means no limit. | Number |
| unlimited | v0.7.0 |
bulk_insert_limit | Maximum number of messages stored with a single SQL "INSERT" statement. The default behavior is to send individual insert commands as part of a SQL transaction. | Number |
|
| v0.20.0 |
最后更新于