mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Updates based on comments
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This commit is contained in:
parent
ea1f66152c
commit
dbe28dcae7
@ -1,14 +1,14 @@
|
|||||||
# NATS Streaming
|
# NATS Streaming
|
||||||
|
|
||||||
Where NATS provides at most once quality of service, streaming adds at least once. Streaming is implemented as a request-reply service on top of NATS. Streaming messages are encoded as protocol buffers, the streaming clients use NATS to talk to the streaming server. The streaming server organizes messages in channels and stores them in files or databases. ACKs are used to insure delivery in both directions.
|
Where NATS provides at most once quality of service, streaming adds at least once. Streaming is implemented as a request-reply service on top of NATS, where streaming messages are encoded as protocol buffers and the streaming clients use NATS to talk to the streaming server. The streaming server organizes messages in channels and stores them in files or databases, using ACKs to ensure delivery in both directions.
|
||||||
|
|
||||||
> Sometimes the maintainers will refer to NATS as "nats core" and streaming as "stan" or "streaming".
|
> Sometimes the maintainers will refer to NATS as "nats core" and streaming as "stan" or "streaming".
|
||||||
|
|
||||||
Messages to the streaming service are opaque byte arrays, just as they are with NATS. However, the streaming server protocol uses protocol buffers to wrap these byte arrays. So if you listen to the NATS traffic the messages will appear as protocol buffers, while the actual data sent and received will simply be byte arrays.
|
Messages to the streaming service are opaque byte arrays, just as they are with NATS. However, the streaming server protocol uses protocol buffers to wrap these byte arrays. So if you listen to the NATS traffic the messages will appear as protocol buffers, while the actual data sent and received will simply be byte arrays.
|
||||||
|
|
||||||
NATS streaming uses the concept of a channel to represent an ordered collection of messages. Clients send to and receive from channels instead of subjects. The subjects used by the streaming libraries and server are managed internally. Channels do not currently support wildcard. Channels aren’t raw subjects. Streaming isn’t raw NATS. The streaming libraries hide some of the differences.
|
NATS streaming uses the concept of a channel to represent an ordered collection of messages. Clients send to and receive from channels instead of subjects. The subjects used by the streaming libraries and server are managed internally. Channels do not currently support wildcards. Channels aren’t raw subjects. Streaming isn’t raw NATS. The streaming libraries hide some of the differences.
|
||||||
|
|
||||||
Think of channels as a First In First Out (FIFO) queue. Messages are added until the configured limit is reached. Old messages are removed to make room for new ones. Old messages can expire, based on configuration. Subscriptions don’t affect channel content, that is, when a message is acknowledged, it is not removed from the channel.
|
Think of channels as a First In First Out (FIFO) queue. Messages are added until the configured limit is reached. Old messages can be set to expire based on configuration, making room for new messages. Subscriptions don’t affect channel content, that is, when a message is acknowledged, it is not removed from the channel.
|
||||||
|
|
||||||
Positions in the channel are specified in multiple ways:
|
Positions in the channel are specified in multiple ways:
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ Positions in the channel are specified in multiple ways:
|
|||||||
* Time
|
* Time
|
||||||
* Time delta (converted to time on client)
|
* Time delta (converted to time on client)
|
||||||
|
|
||||||
New subscriptions can also specify last received to indicate they only want new messages. Sequence numbers are persistent, when message #1 goes away the oldest message is message #2. Trying to go to a position before the oldest message will be moved to the oldest message.
|
New subscriptions can also specify last received to indicate they only want new messages. Sequence numbers are persistent so when message #1 goes away, the oldest message is then message #2. If you try to go to a position before the oldest message, you will be moved to the oldest message.
|
||||||
|
|
||||||
## Subscription Types
|
## Subscription Types
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ Then get the default options and override some of them:
|
|||||||
s, err := stand.RunServerWithOpts(opts, nil)
|
s, err := stand.RunServerWithOpts(opts, nil)
|
||||||
```
|
```
|
||||||
|
|
||||||
However, since the NATS Streaming Server project vendors NATS Server (that it uses as the communication layer with its clients and other servers in the cluster, there are some limitations.
|
However, since the NATS Streaming Server project vendors NATS Server that is uses as the communication layer with its clients and other servers in the cluster, there are some limitations.
|
||||||
|
|
||||||
If you were to import `github.com/nats-io/nats-server/server`, instantiate a NATS `Options` structure, configure it and pass it to the second argument of `RunServerWithOpts`, you would get a compiler error. For instance doing this does not work:
|
If you were to import `github.com/nats-io/nats-server/server`, instantiate a NATS `Options` structure, configure it and pass it to the second argument of `RunServerWithOpts`, you would get a compiler error. For instance doing this does not work:
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ To workaround this issue, the NATS Streaming Server package provides a function
|
|||||||
|
|
||||||
That will work.
|
That will work.
|
||||||
|
|
||||||
But, if you want to do advanced NATS configuration that requires types or interfaces that belong to the NATS Server package, then this approach won't work. In this case you need to run the NATS Server indepently and have the NATS Streaming Server connects to it. Here is how:
|
But, if you want to do advanced NATS configuration that requires types or interfaces that belong to the NATS Server package, then this approach won't work. In this case, you need to run the NATS Server independently and have the NATS Streaming Server connect to it.
|
||||||
|
|
||||||
```
|
```
|
||||||
// This configure the NATS Server using natsd package
|
// This configure the NATS Server using natsd package
|
||||||
@ -108,4 +108,4 @@ But, if you want to do advanced NATS configuration that requires types or interf
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The above seem involved, but it really only if you use very advanced NATS Server options.
|
The above process may seem involved, but only if you use very advanced NATS Server options.
|
@ -1,6 +1,6 @@
|
|||||||
# Writing your own client library
|
# Writing your own client library
|
||||||
|
|
||||||
You can find a list of all supported client libraries [here](https://nats.io/download/). There is also links to community contributed clients.
|
You can find a list of all supported client libraries [here](https://nats.io/download/). There are also links to community contributed clients.
|
||||||
|
|
||||||
In the event you would want to write your own NATS Streaming library, you could have a look at existing libraries to understand the flow. But you need to use [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) to exchange protocols between the client and the server.
|
In the event you would want to write your own NATS Streaming library, you could have a look at existing libraries to understand the flow. But you need to use [Google Protocol Buffers](https://developers.google.com/protocol-buffers/) to exchange protocols between the client and the server.
|
||||||
|
|
||||||
|
@ -6,6 +6,6 @@ After the first queue member is created, any other member joining the group will
|
|||||||
|
|
||||||
When the last member of the group leaves (subscription unsubscribed/closed/or connection closed), the group is removed from the server. The next application creating a subscription with the same name will create a new group, starting at the start position given in the subscription request.
|
When the last member of the group leaves (subscription unsubscribed/closed/or connection closed), the group is removed from the server. The next application creating a subscription with the same name will create a new group, starting at the start position given in the subscription request.
|
||||||
|
|
||||||
A queue subscription can also be durable. For that, the client needs to provide a queue and durable name. The behavior is, as you would expect, a combination of queue and durable subscription. Unlike a durable subscription, though, the client ID is not part of the queue group name. It makes sense, because since client ID must be unique, it would prevent more than one connection to participate in the queue group. The main difference between a queue subscription and a durable one, is that when the last member leaves the group, the state of the group will be maintained by the server. Later, when a member rejoins the group, the delivery will resume.
|
A queue subscription can also be durable. For that, the client needs to provide a queue and durable name. The behavior is, as you would expect, a combination of queue and durable subscription. Though unlike a durable subscription, the client ID is not part of the queue group name since the client ID must be unique, and would prevent more than one connection to participate in the queue group. The main difference between a queue subscription and a durable one, is that when the last member leaves the group, the state of the group will be maintained by the server. Later, when a member rejoins the group, the delivery will resume.
|
||||||
|
|
||||||
***Note: For a durable queue subscription, the last member to * unsubscribe * (not simply close) causes the group to be removed from the server.***
|
***Note: For a durable queue subscription, the last member to * unsubscribe * (not simply close) causes the group to be removed from the server.***
|
||||||
|
Loading…
x
Reference in New Issue
Block a user