Skip to content
Open
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
11 changes: 8 additions & 3 deletions pkg/jetstream/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ func consume(ctx context.Context,
) (chan *message.Message, error) {
output := make(chan *message.Message)

// TODO: this is the closest analog to callback based subscriptions in watermill-nats/pkg/nats
// add support for batching pull consumers using consumer.Fetch / FetchNoWait
// Use Fetch with PullMaxMessages=1 to avoid pre-buffering.
// consumer.Consume() pre-fetches messages internally, causing the NATS ackWait
// clock to start ticking before the handler sees the message. Over time,
// a backlog causes NATS to redeliver messages that were still being processed.
fetchOpts := append([]jetstream.PullConsumeOpt{}, pullConsumeOpts...)
fetchOpts = append(fetchOpts, jetstream.PullMaxMessages(1))

cc, err := consumer.Consume(func(msg jetstream.Msg) {
cb(ctx, msg, output)
}, pullConsumeOpts...)
}, fetchOpts...)
if err != nil {
return nil, fmt.Errorf("failed to start jetstream consumer: %w", err)
}
Expand Down