Skip to content
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 explicit ack/nak for nats jetstream #1073

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion protocol/nats_jetstream/v2/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,24 @@ func (m *Message) ReadBinary(ctx context.Context, encoder binding.BinaryWriter)

// Finish *must* be called when message from a Receiver can be forgotten by the receiver.
func (m *Message) Finish(err error) error {
return nil
// Ignore error if message has already been Ack/Nak.
// Ack and Nak first checks to see if the message has been acknowleged
// and immediately returns an error without applying any logic to the message on the server.
// A message will auto acknowledge unless manual ack is set or policy is set to AckNonePolicy
// see: ManualAck() subscription option
// see: ConsumerConfig.AckPolicy
if err != nil {
errNak := m.Msg.Nak()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are other errors that Ack and Nak can return? Can you please run a local dummy test with a real NATS backend and always return an error here so we understand how the system behaves end-to-end? IMHO it should be fine (warning logged), but want to make sure this doesn't lead to an endless invocation loop since with this change we're changing the behavior for users.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will close this PR if #1095 gets merged.

if errNak == nats.ErrMsgAlreadyAckd || errNak == nats.ErrCantAckIfConsumerAckNone {
return nil
}
return errNak
}
errAck := m.Msg.Ack()
if errAck == nats.ErrMsgAlreadyAckd || errAck == nats.ErrCantAckIfConsumerAckNone {
return nil
}
return errAck
}

// GetAttribute implements binding.MessageMetadataReader
Expand Down