NatsClient is designed to be the entry point for new commers with sensible defaults, like ad-hoc JSON serialization being enabled, whereas NatsConnection usage is more suitable for more advanced setups, giving applications much more control over the system.
With the fixes made in #1041 it is important to setup the connections with optimal values so the client works well under load for most scenarios when there are slow consumers . These are internal buffer (channels in our case) capacities and their overflow behavior. In addition to those, logging dropped messages by default should alert the applications of slow consumers.
When using NatsClient:
- Set
SubPendingChannelCapacity to 16384. This is roughly in line with Go (64MB) and Java (~15L Messages) clients. (please correct me if I'm wrong here)
- Set
SubPendingChannelFullMode = BoundedChannelFullMode.DropNewest
- Deprecate
SubPendingChannelFullMode and set it to DropNewest by default. This is fairly fundamental to NATS's philosophy (see Slow Consumers in docs)
- Listen to
MessageDropped evens and log: Slow consumer detected for {Subject}
NatsClientis designed to be the entry point for new commers with sensible defaults, like ad-hoc JSON serialization being enabled, whereasNatsConnectionusage is more suitable for more advanced setups, giving applications much more control over the system.With the fixes made in #1041 it is important to setup the connections with optimal values so the client works well under load for most scenarios when there are slow consumers . These are internal buffer (channels in our case) capacities and their overflow behavior. In addition to those, logging dropped messages by default should alert the applications of slow consumers.
When using
NatsClient:SubPendingChannelCapacityto16384. This is roughly in line with Go (64MB) and Java (~15L Messages) clients. (please correct me if I'm wrong here)SubPendingChannelFullMode = BoundedChannelFullMode.DropNewestSubPendingChannelFullModeand set it toDropNewestby default. This is fairly fundamental to NATS's philosophy (see Slow Consumers in docs)MessageDroppedevens and log:Slow consumer detected for {Subject}