Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVED] Enhance documentation for PullMaxMessagesWithBytesLimit and PullMaxBytes #1796

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions jetstream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,13 @@ the behavior of a single pull request:

- `PullMaxMessages(int)` - up to provided number of messages will be buffered
- `PullMaxBytes(int)` - up to provided number of bytes will be buffered. This
setting and `PullMaxMessages` are mutually exclusive
setting and `PullMaxMessages` are mutually exclusive.
The value should be set to a high enough value to accommodate the largest
message expected from the server. Note that it may not be sufficient to set
this value to the maximum message size, as this setting controls the client
buffer size, not the max bytes requested from the server within a single pull
request. If the value is set too low, the consumer will stall and not be able
to consume messages.
- `PullExpiry(time.Duration)` - timeout on a single pull request to the server
type PullThresholdMessages int
- `PullThresholdMessages(int)` - amount of messages which triggers refilling the
Expand All @@ -494,10 +500,13 @@ request. An error will be triggered if at least 2 heartbeats are missed
- `WithConsumeErrHandler(func (ConsumeContext, error))` - when used, sets a
custom error handler on `Consume()`, allowing e.g. tracking missing
heartbeats.
- `PullMaxMessagesWithBytesLimit` - up to the provided number of messages
will be buffered and a single fetch size will be limited to the provided
value. This is an advanced option and should be used with caution. Most of the
time, `PullMaxMessages` or `PullMaxBytes` should be used instead.
- `PullMaxMessagesWithBytesLimit` - up to the provided number of messages will
be buffered and a single fetch size will be limited to the provided value.
This is an advanced option and should be used with caution. Most of the time,
`PullMaxMessages` or `PullMaxBytes` should be used instead. Note that he byte
limit should never be set to a value lower than the maximum message size that
can be expected from the server. If the byte limit is lower than the maximum
message size, the consumer will stall and not be able to consume messages.

> __NOTE__: `Stop()` should always be called on `ConsumeContext` to avoid
> leaking goroutines.
Expand Down Expand Up @@ -530,7 +539,13 @@ iter, _ := cons.Messages(jetstream.PullMaxMessages(10), jetstream.PullMaxBytes(1

- `PullMaxMessages(int)` - up to provided number of messages will be buffered
- `PullMaxBytes(int)` - up to provided number of bytes will be buffered. This
setting and `PullMaxMessages` are mutually exclusive
setting and `PullMaxMessages` are mutually exclusive.
The value should be set to a high enough value to accommodate the largest
message expected from the server. Note that it may not be sufficient to set
this value to the maximum message size, as this setting controls the client
buffer size, not the max bytes requested from the server within a single pull
request. If the value is set too low, the consumer will stall and not be able
to consume messages.
- `PullExpiry(time.Duration)` - timeout on a single pull request to the server
type PullThresholdMessages int
- `PullThresholdMessages(int)` - amount of messages which triggers refilling the
Expand All @@ -540,10 +555,13 @@ type PullThresholdMessages int
- `PullHeartbeat(time.Duration)` - idle heartbeat duration for a single pull
request. An error will be triggered if at least 2 heartbeats are missed (unless
`WithMessagesErrOnMissingHeartbeat(false)` is used)
- `PullMaxMessagesWithBytesLimit` - up to the provided number of messages
will be buffered and a single fetch size will be limited to the provided
value. This is an advanced option and should be used with caution. Most of the
time, `PullMaxMessages` or `PullMaxBytes` should be used instead.
- `PullMaxMessagesWithBytesLimit` - up to the provided number of messages will
be buffered and a single fetch size will be limited to the provided value.
This is an advanced option and should be used with caution. Most of the time,
`PullMaxMessages` or `PullMaxBytes` should be used instead. Note that he byte
limit should never be set to a value lower than the maximum message size that
can be expected from the server. If the byte limit is lower than the maximum
message size, the consumer will stall and not be able to consume messages.

##### Using `Messages()` to fetch single messages one by one

Expand Down
12 changes: 12 additions & 0 deletions jetstream/jetstream_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ type pullMaxMessagesWithBytesLimit struct {
// in the client, but rather can serve as a way to limit what nats server will
// have to internally buffer for a single fetch request.
//
// The byte limit should never be set to a value lower than the maximum message
// size that can be expected from the server. If the byte limit is lower than
// the maximum message size, the consumer will stall and not be able to consume
// messages.
//
// This is an advanced option and should be used with caution. Most users should
// use [PullMaxMessages] or [PullMaxBytes] instead.
//
Expand Down Expand Up @@ -209,6 +214,13 @@ func (exp PullExpiry) configureMessages(opts *consumeOpts) error {
// If not provided, the limit is not set (max messages will be used instead).
// This option is exclusive with PullMaxMessages.
//
// The value should be set to a high enough value to accommodate the largest
// message expected from the server. Note that it may not be sufficient to set
// this value to the maximum message size, as this setting controls the client
// buffer size, not the max bytes requested from the server within a single pull
// request. If the value is set too low, the consumer will stall and not be able
// to consume messages.
//
// PullMaxBytes implements both PullConsumeOpt and PullMessagesOpt, allowing
// it to configure Consumer.Consume and Consumer.Messages.
type PullMaxBytes int
Expand Down