Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add NATS Ack/Nak to nats jetstream V3 Finish #1104
Changes from all commits
eb93b65
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
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.