Set AckAll option automatically if batch size is greater than 1

This commit is contained in:
Neil Alexander 2022-08-31 12:03:26 +01:00
parent 4d89e020b3
commit 8e1f004843
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -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 {