Skip to content

Commit

Permalink
Updates to NATS protocol documentation (documentation/internals) (#344)
Browse files Browse the repository at this point in the history
* Updates to NATS protocol documentation (documentation/internals)
  • Loading branch information
gcolliso authored and aricart committed Jun 12, 2018
1 parent a3e0314 commit b3fb44d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions content/documentation/internals/nats-protocol.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
+++
date = "2015-09-27"
title = "NATS Protocol"
date = "2018-06-12"
title = "NATS Client Protocol"
category = "internals"
[menu.main]
name = "NATS Protocol"
name = "NATS Client Protocol"
weight = 1
identifier = "internals-nats-protocol"
parent = "Internals"
+++

# NATS protocol
# NATS Client protocol

The NATS wire protocol is a simple, text-based publish/subscribe style protocol. Clients connect to and communicate with `gnatsd` (the NATS server) through a regular TCP/IP socket using a small set of protocol operations that are terminated by newline.

Unlike traditional messaging systems that use a binary message format that require an API to consume, the text-based NATS protocol makes it easy to implement clients in a wide variety of programming and scripting languages.

The NATS server implements a [zero allocation byte parser](https://youtu.be/ylRKac5kSOk?t=10m46s) that is fast and efficient.

## NATS protocol conventions
## NATS Client protocol conventions

**Subject names**: Subject names, including reply subject (INBOX) names, are case-sensitive and must be non-empty alphanumeric strings with no embedded whitespace, and optionally token-delimited using the dot character (`.`), e.g.:

Expand All @@ -41,7 +41,7 @@ Multiple whitespace characters will be treated as a single field delimiter.
This newline sequence is also used to mark the beginning of the actual message payload in a `PUB` or `MSG` protocol message.


## NATS protocol messages
## NATS Client protocol messages

The following table briefly describes the NATS protocol messages.
NATS protocol operation names are case insensitive, thus `SUB foo 1\r\n` and `sub foo 1\r\n` are equivalent.
Expand Down
32 changes: 16 additions & 16 deletions content/documentation/internals/nats-server-protocol.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
+++
date = "2016-08-24"
title = "NATS Server Protocol"
date = "2018-06-12"
title = "NATS Cluster Protocol"
category = "internals"
[menu.main]
name = "NATS Server Protocol"
name = "NATS Cluster Protocol"
weight = 1
identifier = "internals-nats-server-protocol"
parent = "Internals"
+++

# NATS Server clustering protocol
# NATS Cluster protocol

The NATS server clustering protocol describes the messages passed between NATS servers within a [cluster](/documentation/server/gnatsd-cluster/) to share subscription state, forward messages, and share cluster topology. It is a simple, text-based publish/subscribe style protocol. Servers communicate with each other through a regular TCP/IP socket using a small set of protocol operations that are terminated by newline.

The NATS server implements a [zero allocation byte parser](https://youtu.be/ylRKac5kSOk?t=10m46s) that is fast and efficient.

The NATS server clustering 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.
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 Server protocol conventions
## NATS Cluster protocol conventions

**Subject names and wildcards**: The NATS server protocol has the same features and restrictions as the client with respect to subject names and wildcards, with one addition - a server can publish subjects prefixed with `_SYS.`, which is reserved for messages that are internally generated by a server.
**Subject names and wildcards**: The NATS cluster protocol has the same features and restrictions as the client with respect to subject names and wildcards, with one addition - a server can publish subjects prefixed with `_SYS.`, which is reserved for messages that are internally generated by a server.

**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\n`, `0x0D0A`) to terminate protocol messages. This newline sequence is also used to mark the beginning of the actual message payload in a `PUB` or `MSG` protocol message.


## NATS Server protocol messages
## 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\n` and `sub foo 1\r\n` are equivalent.
Expand Down Expand Up @@ -147,16 +147,16 @@ To publish an empty message to subject NOTIFY:

### Syntax

**Basic Subscription**: `SUB <subject> RSID:<ssid>:<sid>\r\n`
**Basic Subscription**: `SUB <subject> RSID:<cid>:<sid>\r\n`

**Queue Subscription**: `SUB <subject> <queue> QRSID:<ssid:<sid>\r\n`
**Queue Subscription**: `SUB <subject> <queue> QRSID:<cid>:<sid>\r\n`

where:

* `subject`: The subject name to subscribe to
* `queue`: If specified, the subscriber will join this queue group
* `ssid`: A unique alphanumeric subscription ID representing the server's internal subscription
* `sid`: A unique alphanumeric subscription ID representing the client's subscription.
* `cid`: A 64bit unsigned integer representing the client connection
* `sid`: A unique alphanumeric subscription ID representing the server's subscription

### Description

Expand All @@ -176,16 +176,16 @@ To subscribe the current connection to the subject `BAR` as part of distribution

### Syntax

**Basic Subscription**: `UNSUB <sid> RSID:<ssid>:<sid> [max_msgs]\r\n`
**Basic Subscription**: `UNSUB <sid> RSID:<cid>:<sid> [max_msgs]\r\n`

**Queue Subscription**: `UNSUB <sid> QRSID:<ssid>:<sid> [max_msgs]\r\n`
**Queue Subscription**: `UNSUB <sid> QRSID:<cid>:<sid> [max_msgs]\r\n`

where:

* `sid`: The unique alphanumeric subscription ID of the subject to unsubscribe from
* `max_msgs`: Number of messages to wait for before automatically unsubscribing
* `ssid`: A unique alphanumeric subscription ID representing the server's internal subscription
* `sid`: A unique alphanumeric subscription ID representing the client's subscription.
* `cid`: A 64bit unsigned integer representing the client connection
* `sid`: A unique alphanumeric subscription ID representing the server's subscription

### Description

Expand Down

0 comments on commit b3fb44d

Please sign in to comment.