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

Fixing/adding samples, slight reword

Signed-off-by: Matthias Hanel <mh@synadia.com>
This commit is contained in:
Matthias Hanel 2020-02-05 19:30:30 -05:00
parent 51561bc6a6
commit 6fd7324928
2 changed files with 20 additions and 7 deletions

View File

@ -11,6 +11,20 @@ Connection events may include the connection being closed, disconnected or recon
```go
// There is not a single listener for connection events in the NATS Go Client.
// Instead, you can set individual event handlers using:
nc, err := nats.Connect("demo.nats.io",
nats.DisconnectErrHandler(func(_ *nats.Conn, err error) {
log.Printf("client disconnected: %v", err)
}),
nats.ReconnectHandler(func(_ *nats.Conn) {
log.Printf("client reconnected")
}),
nats.ClosedHandler(func(_ *nats.Conn) {
log.Printf("client closed")
}))
if err != nil {
log.Fatal(err)
}
defer nc.Close()
DisconnectHandler(cb ConnHandler)
ReconnectHandler(cb ConnHandler)
@ -114,7 +128,7 @@ await nc.connect(**options)
{% tab title="Ruby" %}
```ruby
r# There is not a single listener for connection events in the Ruby NATS Client.
# There is not a single listener for connection events in the Ruby NATS Client.
# Instead, you can set individual event handlers using:
NATS.on_disconnect do
@ -229,7 +243,7 @@ nc.on('serversDiscovered', (urls) => {
{% tab title="Ruby" %}
```ruby
r# The Ruby NATS client does not support discovered servers handler right now
# The Ruby NATS client does not support discovered servers handler right now
```
{% endtab %}
@ -354,4 +368,3 @@ nc.on('error', (err) => {
```
{% endtab %}
{% endtabs %}

View File

@ -1,8 +1,8 @@
# Slow Consumers
NATS is designed to move messages through the server quickly. As a result, NATS depends on the applications to consider and respond to changing message rates. The server will do a bit of impedance matching, but if a client is too slow the server will eventually cut them off. These cut off connections are called _slow consumers_.
NATS is designed to move messages through the server quickly. As a result, NATS depends on the applications to consider and respond to changing message rates. The server will do a bit of impedance matching, but if a client is too slow the server will eventually cut them off by closing the connection. These cut off connections are called _slow consumers_.
One way some of the libraries deal with bursty message traffic is to cache incoming messages for a subscription. So if an application can handle 10 messages per second and sometimes receives 20 messages per second, the library may hold the extra 10 to give the application time to catch up. To the server, the application will appear to be handling the messages and consider the connection healthy. It is up to the client library to decide what to do when the cache is too big, but most client libraries will drop incoming messages.
One way some of the libraries deal with bursty message traffic is to buffer incoming messages for a subscription. So if an application can handle 10 messages per second and sometimes receives 20 messages per second, the library may hold the extra 10 to give the application time to catch up. To the server, the application will appear to be handling the messages and consider the connection healthy. It is up to the client library to decide what to do when the cache is too big, but most client libraries will drop incoming messages.
Receiving and dropping messages from the server keeps the connection to the server healthy, but creates an application requirement. There are several common patterns:
@ -101,7 +101,7 @@ await nc.subscribe("updates", cb=cb, pending_bytes_limit=5*1024*1024, pending_ms
{% tab title="Ruby" %}
```ruby
# The Ruby NATS client currently does not have option to customize slow consumer limits per sub.
# The Ruby NATS client currently does not have option to customize specify a subscribers pending limits.
```
{% endtab %}
@ -200,7 +200,7 @@ public class SlowConsumerListener {
if len(msgs) == 3:
# Head of line blocking on other messages caused
# by single message proccesing taking long...
# by single message proccesing taking long...
await asyncio.sleep(1)
await nc.subscribe("updates", cb=cb, pending_msgs_limit=5)