NATS文档
  • 欢迎
  • 发行备注
    • 最新情况
      • NATS 2.2
      • NATS 2.0
  • NATS 概念
    • 概览
      • 比较 NATS
    • 什么是NATS
      • 演练安装
    • 基于主题的消息
    • 核心NATS
      • 发布和订阅
        • 发布/订阅演 练
      • 请求和响应
        • 请求/响应 演练
      • 队列组
        • 队列 演练
    • JetStream
      • 流
      • 消费者
        • 示例
      • JetStream 演练
      • 键值对存储
        • 键值对存储演练
      • 对象存储
        • 对象存储演练
    • 主题映射与分区
    • NATS服务器基础架构
      • NATS部署架构适配
    • 安全
    • 连接性
  • 使用 NATS
    • NATS工具
      • nats
        • nats基准测试
      • nk
      • nsc
        • 基础
        • 流
        • 服务
        • 签名密钥
        • 撤销
        • 管理操作
      • nats-top
        • 教程
    • 用NATS开发
      • 一个NATS应用的解剖
      • 连接
        • 连接到默认服务器
        • 连接到特定服务器
        • 连接到群集
        • 连接名称
        • 用用户名和密码做认证
        • 用令牌做认证
        • 用NKey做认证
        • 用一个可信文件做认证
        • 用TLS加密连接
        • 设置连接超时
        • 乒乓协议
        • 关闭响应消息
        • 杂技功能
        • 自动恢复
          • 禁用自动重连
          • 设置自动重新连接的最大次数
          • 随机
          • 重连尝试之间暂停
          • 关注重连事件
          • 重连尝试期间缓存消息
        • 监视连接
          • 关注连接事件
          • 低速消费者
      • 接收消息
        • 同步订阅
        • 异步订阅
        • 取消订阅
        • N个消息后取消订阅
        • 回复一个消息
        • 通配符订阅
        • 队列订阅
        • 断开连接前清除消息
        • 接收结构化数据
      • 发送消息
        • 包含一个回复主题
        • 请求回复语义
        • 缓存刷入和乒
        • 发送结构化数据
      • JetStream
        • 深入JetStream模型
        • 管理流和消费者
        • 消费者详情
        • 发布到流
        • 使用键值对存储
        • 使用对象存储
      • 教程
        • 用go做个自定义拨号器
  • 运行一个NATS服务
    • 安装、运行和部署NATS服务
      • 安装一个NATS服务
      • 运行和部署一个NATS服务
      • Windows服务
      • 信号
    • 环境约束
    • NATS和Docker
      • 教程
      • Docker Swarm
      • Python 和 NGS 运行在Docker
      • JetStream
    • NATS和Kubernetes
      • 用Helm 部署NATS
      • 创建一个Kubernetes群集
      • NATS群集和认证管理
      • 用cfssl保护NATS群集
      • 用负载均衡来保护外部的NATS访问
      • 在Digital Ocean用Helm创建超级NATS群集
      • 使用Helm从0到K8S再到叶子节点
    • NATS服务的客户端
    • 配置 NATS服务
      • 配置 JetStream
        • 配置管理 Management
          • NATS管理命令行
          • 地形
          • GitHub Actions
          • Kubernetes控制器
      • 群集
        • 群集配置
        • JetStream 群集
          • 管理
      • 网关超级群集
        • 配置
      • 叶子节点
        • 配置
        • JetStream在叶子节点
      • 安全加固NATS
        • 使用 TLS
        • 认证
          • 令牌
          • 用户名/密码
          • TLS认证
            • 群集中的TLS认证
          • NKeys
          • 认证超时
          • 去中心化的 JWT 认证/授权
            • 使用解析器查找帐户
            • 内存解析器教程
            • 混合认证/授权安装
        • 授权
        • 基于账户的多租户
        • OCSP Stapling
      • 日志
      • 使用监控
      • MQTT
        • 配置
      • 配置主题映射
      • 系统事件
        • 系统时间和去中心化的JWT教程
      • WebSocket
        • 配置
    • 管理和监控你的NATS服务基础架构
      • 监控
        • 监控 JetStream
      • 管理 JetStream
        • 账号信息
        • 命名流,消费者和账号
        • 流
        • 消费者
        • 数据复制
        • 灾难回复
        • 加密Rest
      • 管理JWT安全
        • 深入JWT指南
      • 升级一个群集
      • 慢消费者
      • 信号
      • 跛脚鸭模式
  • 参考
    • 常见问题
    • NATS协议
      • 协议演示
      • 客户端协议
        • 开发一个客户端
      • NATS群集协议
      • JetStream API参考
  • 遗产
    • STAN='NATS流'
      • STAN概念
        • 和NATS的关系
        • 客户端连接
        • 频道
          • 消息日志
          • 订阅
            • 通常的
            • 持久化的
            • 队列组
            • 重新投递
        • 存储接口
        • 存储加密
        • 群集
          • Supported Stores
          • Configuration
          • Auto Configuration
          • Containers
        • Fault Tolerance
          • Active Server
          • Standby Servers
          • Shared State
          • Failover
        • Partitioning
        • Monitoring
          • Endpoints
      • Developing With STAN
        • Connecting to NATS Streaming Server
        • Publishing to a Channel
        • Receiving Messages from a Channel
        • Durable Subscriptions
        • Queue Subscriptions
        • Acknowledgements
        • The Streaming Protocol
      • STAN NATS Streaming Server
        • Installing
        • Running
        • Configuring
          • Command Line Arguments
          • Configuration File
          • Store Limits
          • Persistence
            • File Store
            • SQL Store
          • Securing
        • Process Signaling
        • Windows Service
        • Embedding NATS Streaming Server
        • Docker Swarm
        • Kubernetes
          • NATS Streaming with Fault Tolerance.
    • nats账号服务
      • Basics
      • Inspecting JWTs
      • Directory Store
      • Update Notifications
由 GitBook 提供支持
在本页
  • NATS Cluster Protocol
  • NATS Cluster protocol conventions
  • NATS Cluster protocol messages
  • INFO
  • Description
  • Syntax
  • Example
  • CONNECT
  • Description
  • Syntax
  • Example
  • RS+
  • Description
  • Syntax
  • RS-
  • Description
  • Syntax
  • RMSG
  • Description
  • Syntax
  • PING/PONG
  • Description
  • Syntax
  • -ERR
  • Description
  1. 参考
  2. NATS协议

NATS群集协议

上一页开发一个客户端下一页JetStream API参考

最后更新于2年前

NATS Cluster Protocol

The NATS server clustering protocol describes the protocols passed between NATS servers within a to share accounts, subscriptions, forward messages, and share cluster topology regarding new servers. It is a simple text-based protocol. Servers communicate with each other through a regular TCP/IP or TLS socket using a small set of protocol operations that are terminated by newline.

The NATS server implements a that is fast and efficient.

The NATS cluster protocol is very similar to that of the NATS client protocol. In the context of a cluster, it can be helpful to visualize a server being a proxy operating on behalf of its connected clients, subscribing, unsubscribing, sending and receiving messages.

NATS Cluster protocol conventions

Subject names and wildcards: The NATS cluster protocol has the same features and restrictions as the client with respect to subject names and wildcards. Clients are bound to a single account, however the cluster protocol handles all accounts.

Field Delimiters: The fields of NATS protocol messages are delimited by whitespace characters '`'\(space\) or\t` (tab). Multiple whitespace characters will be treated as a single field delimiter.

Newlines: Like other text-based protocols, NATS uses CR followed by LF (CR+LF, \r, 0x0D0A) to terminate protocol messages. This newline sequence is also used to mark the beginning of the actual message payload in a RMSG protocol message.

NATS Cluster protocol messages

The following table briefly describes the NATS cluster protocol messages. As in the client protocol, the NATS protocol operation names are case insensitive, thus SUB foo 1\r and sub foo 1\r are equivalent.

Click the name to see more detailed information, including syntax:

OP Name
Sent By
Description

All Servers

Sent after initial TCP/IP connection and to update cluster knowledge

All Servers

Sent to establish a route

All Servers

Subscribes to a subject for a given account on behalf of interested clients.

All Servers

Unsubscribe (or auto-unsubscribe) from subject for a given account.

Origin Server

Delivers a message for a given subject and account to another server.

All Servers

PING keep-alive message

All Servers

PONG keep-alive response

All Servers

Indicates a protocol error. May cause the remote server to disconnect.

The following sections explain each protocol message.

INFO

Description

As soon as the server accepts a connection from another server, it will send information about itself and the configuration and security requirements that are necessary for the other server to successfully authenticate with the server and exchange messages.

The connecting server also sends an INFO message. The accepting server will add an ip field containing the address and port of the connecting server, and forward the new server's INFO message to all servers it is routed to.

Any servers in a cluster receiving an INFO message with an ip field will attempt to connect to the server at that address, unless already connected. This propagation of INFO messages on behalf of a connecting server provides automatic discovery of new servers joining a cluster.

Syntax

INFO {["option_name":option_value],...}

The valid options are as follows:

  • server_id: The unique identifier of the NATS server

  • version: The version of the NATS server

  • go: The version of golang the NATS server was built with

  • host: The host specified in the cluster parameter/options

  • port: The port number specified in the cluster parameter/options

  • auth_required: If this is set, then the server should try to authenticate upon connect.

  • tls_required: If this is set, then the server must authenticate using TLS.

  • max_payload: Maximum payload size that the server will accept.

  • connect_urls : A list of server urls that a client can connect to.

  • ip: Optional route connection address of a server, nats-route://<hostname>:<port>

Example

Below is an example of an INFO string received by a NATS server, with the ip field.

INFO {"server_id":"KP19vTlB417XElnv8kKaC5","version":"2.0.0","go":"","host":"localhost","port":5222,"auth_required":false,"tls_required":false,"tls_verify":false,"max_payload":1048576,"ip":"nats-route://127.0.0.1:5222/","connect_urls":["localhost:4222"]}

CONNECT

Description

Syntax

CONNECT {["option_name":option_value],...}

The valid options are as follows:

  • tls_required: Indicates whether the server requires an SSL connection.

  • auth_token: Authorization token

  • user: Connection username (if auth_required is set)

  • pass: Connection password (if auth_required is set)

  • name: Generated Server Name

  • lang: The implementation language of the server (go).

  • version: The version of the server.

Example

Here is an example from the default string from a server.

CONNECT {"tls_required":false,"name":"wt0vffeQyoDGMVBC2aKX0b"}\r

RS+

Description

RS+ initiates a subscription to a subject on on a given account, optionally with a distributed queue group name and weighting factor. Note that queue subscriptions will use RS+ for increases and descreases to queue weight except when the weighting factor is 0.

Syntax

Subscription: RS+ <account> <subject>\r

Queue Subscription: RS+ <account> <subject> <queue> <weight>\r

where:

  • account: The account associated with the subject interest

  • subject: The subject

  • queue: Optional queue group name

  • weight: Optional queue group weight representing how much interest/subscribers

RS-

Description

RS- unsubcribes from the specified subject on the given account. It is sent by a server when it no longer has interest in a given subject.

Syntax

Subscription: RS- <account> <subject>\r

where:

  • account: The account associated with the subject interest

  • subject: The subject

RMSG

Description

The RMSG protocol message delivers a message to another server.

Syntax

RMSG <account> <subject> [reply-to] <#bytes>\r\n[payload]\r

where:

  • account: The account associated with the subject interest

  • subject: Subject name this message was received on

  • reply-to: The optional reply subject

  • #bytes: Size of the payload in bytes

  • payload: The message payload data

PING/PONG

Description

PING and PONG implement a simple keep-alive mechanism between servers. Once two servers establish a connection with each other, the NATS server will continuously send PING messages to other servers at a configurable interval. If another server fails to respond with a PONG message within the configured response interval, the server will terminate its connection. If your connection stays idle for too long, it is cut off.

If the another server sends a ping request, a server will reply with a pong message to notify the other server that it is still present.

Syntax

PING\r PONG\r

-ERR

Description

The -ERR message is used by the server to indicate a protocol, authorization, or other runtime connection error to another server. Most of these errors result in the remote server closing the connection.

The CONNECT message is analogous to the message. Once the NATS server has established a TCP/IP socket connection with another server, and an message has been received, the server will send a CONNECT message to provide more information about the current connection as well as security information.

cluster
zero allocation byte parser
INFO
INFO
INFO
CONNECT
RS+
RS-
RMSG
PING
PONG
-ERR