From 8e1f0048436cf39b1592d1577b3f846f6e939001 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 31 Aug 2022 12:03:26 +0100 Subject: [PATCH] Set `AckAll` option automatically if batch size is greater than 1 --- setup/jetstream/helpers.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/setup/jetstream/helpers.go b/setup/jetstream/helpers.go index df82a80cc..f47637c69 100644 --- a/setup/jetstream/helpers.go +++ b/setup/jetstream/helpers.go @@ -34,6 +34,14 @@ func JetStreamConsumer( } }() + // If the batch size is greater than 1, we will want to acknowledge all + // received messages in the batch. Below we will send an acknowledgement + // for the most recent message in the batch and AckAll will ensure that + // all messages that came before it are also acknowledged implicitly. + if batch > 1 { + opts = append(opts, nats.AckAll()) + } + name := durable + "Pull" sub, err := js.PullSubscribe(subj, name, opts...) if err != nil {