NATS 中文文档
  • 引言
  • 发布日志
  • NATS 2.0
  • 对比 NATS
  • FAQ
  • NATS Concepts
    • What is NATS
    • Subject-Based Messaging
    • Publish-Subscribe
    • Request-Reply
    • Queue Groups
    • Acknowledgements
    • Sequence Numbers
  • Developing With NATS
    • Introduction
    • Connecting
      • Connecting to the Default Server
      • Connecting to a Specific Server
      • Connecting to a Cluster
      • Connection Name
      • Setting a Connect Timeout
      • Ping/Pong Protocol
      • Turning Off Echo'd Messages
      • Miscellaneous functionalities
    • Automatic Reconnections
      • Disabling Reconnect
      • Set the Number of Reconnect Attempts
      • Avoiding the Thundering Herd
      • Pausing Between Reconnect Attempts
      • Listening for Reconnect Events
      • Buffering Messages During Reconnect Attempts
    • Securing Connections
      • Authenticating with a User and Password
      • Authenticating with a Token
      • Authenticating with an NKey
      • Authenticating with a Credentials File
      • Encrypting Connections with TLS
    • Receiving Messages
      • Synchronous Subscriptions
      • Asynchronous Subscriptions
      • Unsubscribing
      • Unsubscribing After N Messages
      • Replying to a Message
      • Wildcard Subscriptions
      • Queue Subscriptions
      • Draining Messages Before Disconnect
      • Structured Data
    • Sending Messages
      • Including a Reply Subject
      • Request-Reply Semantics
      • Caches, Flush and Ping
      • Sending Structured Data
    • Monitoring the Connection
      • Listen for Connection Events
      • Slow Consumers
    • Tutorials
      • Explore NATS Pub/Sub
      • Explore NATS Request/Reply
      • Explore NATS Queueing
      • Advanced Connect and Custom Dialer in Go
  • NATS Server
    • Installing
    • Running
      • Windows Service
    • Clients
    • Flags
    • Configuration
      • Securing NATS
        • Enabling TLS
        • Authentication
          • Tokens
          • Username/Password
          • TLS Authentication
          • NKeys
          • Authentication Timeout
        • Authorization
        • Multi Tenancy using Accounts
        • Decentralized JWT Authentication/Authorization
          • Account lookup using Resolver
          • Memory Resolver Tutorial
          • Mixed Authentication/Authorization Setup
      • Clustering
        • Configuration
        • TLS Authentication
      • Super-cluster with Gateways
        • Configuration
      • Leaf Nodes
        • Configuration
      • Logging
      • Monitoring
      • System Events
        • System Events & Decentralized JWT Tutorial
    • Managing A NATS Server
      • Upgrading a Cluster
      • Slow Consumers
      • Signals
    • NATS and Docker
      • Tutorial
      • Docker Swarm
      • Python and NGS Running in Docker
  • NATS Tools
    • Introduction
    • mkpasswd
    • nk
    • nsc
      • Basics
      • Streams
      • Services
      • Signing Keys
      • Revocation
      • Managed Operators
    • nats-account-server
      • Basics
      • Inspecting JWTs
      • Directory Store
      • Update Notifications
    • nats-top
      • Tutorial
    • nats-bench
  • NATS Streaming Concepts
    • Introduction
    • Relation to NATS
    • Client Connections
    • Channels
      • Message Log
      • Subscriptions
        • Regular
        • Durable
        • Queue Group
        • Redelivery
    • Store Interface
    • Store Encryption
    • Clustering
      • Supported Stores
      • Configuration
      • Auto Configuration
      • Containers
    • Fault Tolerance
      • Active Server
      • Standby Servers
      • Shared State
      • Failover
    • Partitioning
    • Monitoring
      • Endpoints
  • Developing With NATS Streaming
    • Introduction
    • Connecting to NATS Streaming
    • Publishing to a Channel
    • Receiving Messages from a Channel
    • Durable Subscriptions
    • Queue Subscriptions
    • Acknowledgements
    • The Streaming Protocol
  • NATS Streaming Server
    • Important Changes
    • Installing
    • Running
    • Configuring
      • Command Line Arguments
      • Configuration File
      • Store Limits
      • 持久化
        • 文件存储
        • SQL 存储
      • Securing
    • Process Signaling
    • Windows Service
    • Embedding NATS Streaming Server
    • Docker Swarm
  • NATS Protocol
    • Protocol Demo
    • Client Protocol
      • Developing a Client
    • NATS Cluster Protocol
  • 在 Kubernetes中使用NATS
    • 序言
    • 安装 NATS 和 NATS Streaming
    • 创建一个 Kubernetes 集群
    • 容错(Fault Tolerance)模式下的NATS Streaming 集群
    • NATS 和 Prometheus Operator
    • NATS 集群和证书管理
    • 使用 cfssl 来提高 NATS 集群的安全性
    • 使用负载均衡器(Load Balancer) 为NATS提供外部访问
    • 使用Helm在Digital Ocean 创建一个NATS 超级集群
    • 使用Helm从0到 K8s到 子节点
由 GitBook 提供支持
在本页
  • Strings and Numbers
  • Variables
  • Include Directive
  • Configuration Properties
  • Connectivity
  • Connection Timeouts
  • Limits
  • Authentication and Authorization
  • Runtime Configuration
  • Monitoring and Tracing
  • Configuration Reloading

这有帮助吗?

  1. NATS Server

Configuration

While the NATS server has many flags that allow for simple testing of features, the NATS server products provide a flexible configuration format that combines the best of traditional formats and newer styles such as JSON and YAML.

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

  • 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

Strings and Numbers

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:

listen: 127.0.0.1:4222
authorization: {
    # BAD!
    token: 3secret
}

Fixed Config:

listen: 127.0.0.1:4222
authorization: {
    token: "3secret"
}

Variables

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

If the environment variable value begins with a number you may have trouble resolving it depending on the server version you are running.

# Define a variable in the config
TOKEN: "secret"

# Reference the variable
authorization {
    token: $TOKEN
}

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

Include Directive

The include directive allows you to split a server configuration into several files. This is useful for separating configuration into chunks that you can easily reuse between different servers.

Includes must use relative paths, and are relative to the main configuration (the one specified via the -c option):

server.conf:

listen: 127.0.0.1:4222
include ./auth.conf

Note that include is not followed by = or :, as it is a directive.

auth.conf:

authorization: {
    token: "f0oBar"
}
> nats-server -c server.conf

Configuration Properties

Connectivity

Property

Description

Default

host

Host for client connections.

0.0.0.0

port

Port for client connections.

4222

listen

Listen specification <host>:<port> for client connections. Either use this or the options host and/or port.

same as host, port

client_advertise

Advertise what host and port specify.

Configuration map for tls for client and http monitoring.

Connection Timeouts

Property

Description

Default

ping_interval

"2m"

ping_max

After how many unanswered pings the server will allow before closing the connection.

2

write_deadline

"2s"

Limits

Property

Description

Default

max_connections

Maximum number of active client connections.

64K

max_control_line

4Kb

max_payload

1Mb

max_pending

Maximum number of bytes buffered for a connection Applies to client connections.

64Mb

max_subscriptions

Maximum numbers of subscriptions per client and leafnode accounts connection.

0, unlimited

Authentication and Authorization

Centralized Authentication and Authorization

Property

Description

Configuration map for client authentication/authorization.

Configuration map for multi tenancy via accounts.

Decentralized Authentication and Authorization

Property

Description

Path to an operator JWT.

Runtime Configuration

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.

false, cache enabled

lame_duck_duration

"2m"

Monitoring and Tracing

Property

Description

Default

server_name

The servers name, shows up in logging. Defaults to the server's id.

Generated Server ID

trace

If true enable protocol trace log messages. Excludes the system account.

false, disabled

trace_verbose

If true enable protocol trace log messages. Includes the system account.

false, disabled

debug

If true enable debug log messages

false, disabled

logtime

If set to false, log without timestamps

true, include timestamp

log_file

Log file name, relative to...

No log file

Size in bytes after the log file rolls over to a new one

0, unlimited

max_traced_msg_len

Set a limit to the trace of the payload of a message.

0, unlimited

syslog

Log to syslog.

false, disabled

remote_syslog

http port for server monitoring.

Listen specification <host>:<port>for server monitoring.

https port for server monitoring. This is influenced by the tls property.

base path for monitoring endpoints.

/

Listen specification <host>:<port>for TLS server monitoring.

system_account

pid_file

port_file_dir

Directory to write a file containing the servers open ports to, relative to ...

connect_error_reports

Number of attempts at which a repeated failed route, gateway or leaf node connection is reported. Connect attempts are made once every second.

3600, approx every hour

reconnect_error_reports

Number of failed attempt to reconnect a route, gateway or leaf node connection. Default is to report every attempt.

1, every failed attempt

Configuration Reloading

> nats-server --signal reload
上一页Flags下一页Securing NATS

最后更新于4年前

这有帮助吗?

Alternative client listen specification <host>:<port> or just <host> to advertise to clients and other server. Useful in setups with NAT.

Configuration map for .

Configuration map for .

Configuration map for a .

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 .

Maximum number of seconds the server will block when writing. Once this threshold is exceeded the connection will be closed. See on how to deal with this on the client.

Maximum length of a protocol line (including combined length of subject and queue group). Increasing this value may require to be used. Applies to all traffic.

Maximum number of bytes in a message payload. Reducing this size may force you to implement in your clients. Applies to client and leafnode payloads.

present in the or an . A client connecting without any form of authentication will be associated with this user, its permissions and account.

The Configuration options here refer to based authentication and authorization.

Resolver type or for account JWTs. (When the operator JWT contains an account URL, it will be used as default. In this case resolver is only needed to overwrite the default.)

for tls connections to the resolver. (This is for an outgoing connection and therefore does not use timeout, verify and map_and_verify)

to preload account public keys and their corresponding JWT. Keys consist of <account public nkey>, value is the <corresponding jwt>. Only used when resolver=MEMORY.

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: .

address.

Name of the system account. Users of this account can subscribe to system events. See for more details.

File containing PID, relative to ... This can serve as input to

A server can reload most configuration changes without requiring a server restart or clients to disconnect by sending the nats-server a :

JWT
signal
cluster
tls
cluster
cluster
gateway
leafnode
leafnode
clients use
slow consumer
authorization
accounts
Username
authorization block
account
tls configuration map
nats-server --signal ldm
http_port
http
https_port
http_base_path
https
System Accounts
nats-server --signal
client changes
chunking
no_auth_user
log_size_limit
Syslog server
operator
resolver
gateway
MEMORY
URL(<url>)
resolver_tls
resolver_preload
Map