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

Update unsub_after.md

This commit is contained in:
Ginger Collison 2020-02-06 12:04:17 -06:00 committed by GitHub
parent d55fabce9b
commit f679971b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,9 +2,9 @@
NATS provides a special form of unsubscribe that is configured with a message count and takes effect when that many messages are sent to a subscriber. This mechanism is very useful if only a single message is expected.
The message count you provide is the total message count for a subscriber. So if you unsubscribe with a count of 1, the server will stop sending messages to that subscription after it has received one message. If the subscriber has already received one or more messages, the unsubscribe will be immediate. This action based on history can be confusing if you try to auto unsubscribe on a long running subscription, but is logical for a new one.
The message count you provide is the total message count for a subscriber. So if you unsubscribe with a count of 1, the server will stop sending messages to that subscription after it has received one message. If the subscriber has already received one or more messages, the unsubscribe will be immediate. This action based on history can be confusing if you try to auto-unsubscribe on a long running subscription, but is logical for a new one.
Auto unsubscribe is based on the total messages sent to a subscriber, not just the new ones. Most of the client libraries also track the max message count after an auto unsubscribe request. On reconnect, this enables clients to resend the unsubscribe with an updated total.
Auto-unsubscribe is based on the total messages sent to a subscriber, not just the new ones. Most of the client libraries also track the max message count after an auto-unsubscribe request. On reconnect, this enables clients to resend the unsubscribe with an updated total.
The following example shows unsubscribe after a single message:
@ -63,7 +63,7 @@ nc.close();
let nc = NATS.connect({
url: "nats://demo.nats.io:4222"
});
// `max` specifies the number of messages that the server will forward.
// `max` specifies the number of messages that the server will forward
// The server will auto-cancel.
let opts = {max: 10};
let sub = nc.subscribe(NATS.createInbox(), opts, (msg) => {
@ -127,8 +127,8 @@ end
{% tab title="TypeScript" %}
```typescript
// `max` specifies the number of messages that the server will forward.
// The server will auto-cancel.
// `max` specifies the number of messages that the server will forward
// The server will auto-cancel
let opts = {max: 10};
let sub = await nc.subscribe(createInbox(), (err, msg) => {
t.log(msg.data);