-
Notifications
You must be signed in to change notification settings - Fork 224
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
Add NATS Ack/Nak to nats jetstream V3 Finish #1104
Conversation
d1cc87c
to
f70c234
Compare
f70c234
to
9b563bd
Compare
err: errors.New("unknown"), | ||
}, | ||
wants: wants{ | ||
err: nil, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we're slurping the error and returning nil
? Is this the correct behavior when finishing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the previous behavior. I am open to changing this behavior if there is support to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, good question if we want consistency (but ambiguous behavior) or fix it. What do you think? Perhaps someone using v3
would not use the prior implementations and therefore we should do what's right for users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at
https://github.com/cloudevents/sdk-go/blob/main/v2/client/client.go#L263
and
https://github.com/cloudevents/sdk-go/blob/main/v2/client/invoker.go#L59
I believe the error returned from Finish is only used for logging:
cecontext.LoggerFrom(ctx).Warn("Error while handling a message: ", err)
So the real question is more about whether we should call Ack() or Nak() in the unknown error case.
In the case that Ack() or Nak() is not called, the ACK/NACK behavior on the server is based on how the NATS consumer is setup.
There are three options: AckNonePolicy, AckAllPolicy, AckExplicitPolicy
So I would think if you had AckNonePolicy or AckAllPolicy, not calling Ack() would result in the server auto-acking.
If you had AckExplicitPolicy set, then failing to call Ack() would result in the message being redelivered.
This might be correct as it would "default" to how the user setup the consumer.
NATS has a MaxDeliver option which would give up after the sending "MaxDeliver times", but the default is "unlimited".
I am inclined to give the user the benefit of defining that behavior, but I am not married to that feeling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that sounds reasonable! Feel free to document the behavior e.g., adding a README or code comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment.
}, | ||
}, | ||
{ | ||
name: "jetstream.ErrMsgAlreadyAckd error returned from Nak", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, there's a case when a (protocol) NACK would contain NATS ACK-ed in this implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nak and ack make the same NATS call deep down with a minor difference in the ackType argument passed via the API. The ErrMsgAlreadyAckd error that comes back simply means that the message has been already "marked" as having been processed. It is used for both ack and nak.
In practice, a message should not be marked ack or nak before calling Finish. But there may be cases where a binding may have a behavior to handle MalformedEvent or a responder may be interjected. In these cases, I believe Finish will still only called once. The error check is simply there to not send back an error in the unlikely case somehow Finish is called more than once.
Head branch was pushed to by a user without write access
9b563bd
to
8d97952
Compare
Signed-off-by: stephen-totty-hpe <stephen.totty@hpe.com>
8d97952
to
eb93b65
Compare
In some cases, an explicit ACK/NACK may be necessary. Currently, there is no way to NACK a message. Also, in some cases, the NATS server may not automatically ACK a message.
This logic explicitly looks for an error that is
protocol.ResultNACK
, for when to do aNak
.If the error is
nil
orprotocol.ResultACK
, then aAck
is done.When an unknown error occurs, the original behavior of
return nil
is invoked.Testing with a live system can be done by temporarily modifying:
https://github.com/cloudevents/sdk-go/blob/main/v2/protocol/test/test.go#L41
that is called from:
https://github.com/cloudevents/sdk-go/blob/main/test/integration/nats_jetstream/v3/nats_test.go#L29