mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-03-03 17:03:10 -06:00
Looks like AckAll won't work on a pull subscription
This commit is contained in:
parent
7c837c57c4
commit
92c4a96003
|
|
@ -34,14 +34,6 @@ 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"
|
name := durable + "Pull"
|
||||||
sub, err := js.PullSubscribe(subj, name, opts...)
|
sub, err := js.PullSubscribe(subj, name, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -49,6 +41,7 @@ func JetStreamConsumer(
|
||||||
return fmt.Errorf("nats.SubscribeSync: %w", err)
|
return fmt.Errorf("nats.SubscribeSync: %w", err)
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
|
nextmsg:
|
||||||
for {
|
for {
|
||||||
// If the parent context has given up then there's no point in
|
// If the parent context has given up then there's no point in
|
||||||
// carrying on doing anything, so stop the listener.
|
// carrying on doing anything, so stop the listener.
|
||||||
|
|
@ -89,21 +82,26 @@ func JetStreamConsumer(
|
||||||
if len(msgs) < 1 {
|
if len(msgs) < 1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
msg := msgs[len(msgs)-1] // most recent message, in case of AckAll
|
for _, msg := range msgs {
|
||||||
if err = msg.InProgress(nats.Context(ctx)); err != nil {
|
if err = msg.InProgress(nats.Context(ctx)); err != nil {
|
||||||
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.InProgress: %w", err))
|
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.InProgress: %w", err))
|
||||||
sentry.CaptureException(err)
|
sentry.CaptureException(err)
|
||||||
continue
|
continue nextmsg
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if f(ctx, msgs) {
|
if f(ctx, msgs) {
|
||||||
if err = msg.AckSync(nats.Context(ctx)); err != nil {
|
for _, msg := range msgs {
|
||||||
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.AckSync: %w", err))
|
if err = msg.AckSync(nats.Context(ctx)); err != nil {
|
||||||
sentry.CaptureException(err)
|
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.AckSync: %w", err))
|
||||||
|
sentry.CaptureException(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = msg.Nak(nats.Context(ctx)); err != nil {
|
for _, msg := range msgs {
|
||||||
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.Nak: %w", err))
|
if err = msg.Nak(nats.Context(ctx)); err != nil {
|
||||||
sentry.CaptureException(err)
|
logrus.WithContext(ctx).WithField("subject", subj).Warn(fmt.Errorf("msg.Nak: %w", err))
|
||||||
|
sentry.CaptureException(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue