1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00

Changing protocol to miscelaneous, adding links, clarifying usage.

Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
Matthias Hanel 2020-03-11 19:07:11 -04:00
parent c36e4d018e
commit f769d89221
2 changed files with 75 additions and 62 deletions

View File

@ -25,8 +25,8 @@
* [Connection Name](developing-with-nats/connecting/name.md) * [Connection Name](developing-with-nats/connecting/name.md)
* [Setting a Connect Timeout](developing-with-nats/connecting/connect_timeout.md) * [Setting a Connect Timeout](developing-with-nats/connecting/connect_timeout.md)
* [Ping/Pong Protocol](developing-with-nats/connecting/pingpong.md) * [Ping/Pong Protocol](developing-with-nats/connecting/pingpong.md)
* [Controlling the Client/Server Protocol](developing-with-nats/connecting/protocol.md)
* [Turning Off Echo'd Messages](developing-with-nats/connecting/noecho.md) * [Turning Off Echo'd Messages](developing-with-nats/connecting/noecho.md)
* [Miscellaneous functionalities](developing-with-nats/connecting/misc.md)
* [Automatic Reconnections](developing-with-nats/reconnect/README.md) * [Automatic Reconnections](developing-with-nats/reconnect/README.md)
* [Disabling Reconnect](developing-with-nats/reconnect/disable.md) * [Disabling Reconnect](developing-with-nats/reconnect/disable.md)
* [Set the Number of Reconnect Attempts](developing-with-nats/reconnect/max.md) * [Set the Number of Reconnect Attempts](developing-with-nats/reconnect/max.md)

View File

@ -1,66 +1,10 @@
# Controlling the Client/Server Protocol # Miscellaneous Functionalities
The protocol between the client and the server is fairly simple and relies on a control line and sometimes a body. The control line contains the operations being sent, like PING or PONG, followed by a carriage return and line feed, CRLF or "\r\n". The server has a setting that can limit the maximum size of a control line. For PING and PONG this doesn't come into play, but for messages that contain subject names, the control line length can be important. The server is also configured with a maximum payload size, which limits the size of a message body. The server sends the maximum payload size to the client at connect time but doesn't currently tell the client the maximum control line size. This section contains miscellaneous functionalities and options for connect.
## Set the Maximum Control Line Size
Some clients will try to limit the control line size internally to prevent an error from the server. These clients may or may not allow you to set the size being used, but if they do, the size should be set to match the server configuration.
For example, to set the maximum control line size to 2k:
{% tabs %}
{% tab title="Go" %}
```go
// This does not apply to the NATS Go Client
```
{% endtab %}
{% tab title="Java" %}
```java
Options options = new Options.Builder().
server("nats://demo.nats.io:4222").
maxControlLine(2 * 1024). // Set the max control line to 2k
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();
```
{% endtab %}
{% tab title="JavaScript" %}
```javascript
// set this option before creating a connection
NATS.MAX_CONTROL_LINE_SIZE = 1024*2;
let nc = NATS.connect({
url: "nats://demo.nats.io:4222"
});
```
{% endtab %}
{% tab title="Python" %}
```python
# Asyncio NATS client does not allow custom control lines.
```
{% endtab %}
{% tab title="Ruby" %}
```ruby
# There is no need to customize this in the Ruby NATS client.
```
{% endtab %}
{% tab title="TypeScript" %}
```typescript
// control line size is not configurable on TypeScript NATS client.
```
{% endtab %}
{% endtabs %}
## Get the Maximum Payload Size ## Get the Maximum Payload Size
While the client can't control the maximum payload size, clients may provide a way for applications to get the size after the connection is made. This will allow the application to chunk or limit data as needed to pass through the server. While the client can't control the maximum payload size, clients may provide a way for applications to obtain the configured [`max_payload`](../../nats-server/configuration/README.md#limits) after the connection is made. This will allow the application to chunk or limit data as needed to pass through the server.
{% tabs %} {% tabs %}
{% tab title="Go" %} {% tab title="Go" %}
@ -149,7 +93,11 @@ nc.on('connect', (nc: Client, url: string, options: ServerInfo) => {
## Turn On Pedantic Mode ## Turn On Pedantic Mode
The NATS server provides a _pedantic_ mode that does extra checks on the protocol. By default, this setting is off but you can turn it on: The NATS server provides a _pedantic_ mode that performs extra checks on the protocol.
One example of such a check is if a subject used for publishing contains a [wildcard](../../nats-concepts/subjects.md#wildcards) character. The server will not use it as wildcard and therefore omits this check.
By default, this setting is off but you can turn it on to test your application:
{% tabs %} {% tabs %}
{% tab title="Go" %} {% tab title="Go" %}
@ -232,9 +180,74 @@ nc.close();
{% endtab %} {% endtab %}
{% endtabs %} {% endtabs %}
## Set the Maximum Control Line Size
The protocol between the client and the server is fairly simple and relies on a control line and sometimes a body. The control line contains the operations being sent, like PING or PONG, followed by a carriage return and line feed, CRLF or "\r\n".
The server has a [`max_control_line`](../../nats-server/configuration/README.md#limits) option that can limit the maximum size of a control line. For PING and PONG this doesn't come into play, but for messages that contain subject names and possibly queue group names, the control line length can be important as it effectively limits the possibly combined length.
Some clients will try to limit the control line size internally to prevent an error from the server. These clients may or may not allow you to set the size being used, but if they do, the size should be set to match the server configuration.
> It is not recommended to set this to a value that is higher than the one of other clients or the nats-server.
For example, to set the maximum control line size to 2k:
{% tabs %}
{% tab title="Go" %}
```go
// This does not apply to the NATS Go Client
```
{% endtab %}
{% tab title="Java" %}
```java
Options options = new Options.Builder().
server("nats://demo.nats.io:4222").
maxControlLine(2 * 1024). // Set the max control line to 2k
build();
Connection nc = Nats.connect(options);
// Do something with the connection
nc.close();
```
{% endtab %}
{% tab title="JavaScript" %}
```javascript
// set this option before creating a connection
NATS.MAX_CONTROL_LINE_SIZE = 1024*2;
let nc = NATS.connect({
url: "nats://demo.nats.io:4222"
});
```
{% endtab %}
{% tab title="Python" %}
```python
# Asyncio NATS client does not allow custom control lines.
```
{% endtab %}
{% tab title="Ruby" %}
```ruby
# There is no need to customize this in the Ruby NATS client.
```
{% endtab %}
{% tab title="TypeScript" %}
```typescript
// control line size is not configurable on TypeScript NATS client.
```
{% endtab %}
{% endtabs %}
## Turn On/Off Verbose Mode ## Turn On/Off Verbose Mode
The NATS server also provide a _verbose_ mode. By default, verbose mode is enabled and the server will reply to every message from the client with either a +OK or a -ERR. Most clients turn off verbose mode, which disables all of the +OK traffic. Errors are rarely subject to verbose mode and client libraries handle them as documented. To turn on verbose mode, likely for testing: Clients can request _verbose_ mode from NATS server. When requested by a client, the server will reply to every message from that client with either a +OK or an error -ERR. However, the client will not block and wait for a response. Errors will be sent without verbose mode as well and client libraries handle them as documented.
> This functionality is only used for debugging the client library or the nats-server themselves.
> By default the server sets it to on, but every client turns it off.
To turn on verbose mode:
{% tabs %} {% tabs %}
{% tab title="Go" %} {% tab title="Go" %}