Navigation Menu

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

Added BackOff helper method to set backoff through subOpts #933

Merged
merged 2 commits into from Apr 4, 2022

Conversation

mfaizanse
Copy link
Contributor

  • Added BackOff helper method to set backoff through subOpts

@coveralls
Copy link

coveralls commented Mar 22, 2022

Coverage Status

Coverage increased (+0.2%) to 85.307% when pulling c47689c on mfaizanse:backoff_sub_opt into e0e03e3 on nats-io:main.

@derekcollison
Copy link
Member

What is the goal of this change? For true push I am worried that this could collide with flow (or lack thereof) and cause memory bloat in the client app.

Could be useful maybe for when you do a pull request however but best to understand what the exact intent is here.

@mfaizanse
Copy link
Contributor Author

mfaizanse commented Mar 23, 2022

The NAK delay and backOff is implemented in these PRs: nats-server and nats-go.

Currently, in the API for to create a consumer, we can set the BackOff but if we create a subscriber then we don't have the Opts method to set the BackOff. The goal of this PR is to enable the user to set the BackOff when creating through a subscriber like this:

// Create a subscriber
	_, err = js.Subscribe(
		subject,
		callback,
		nats.Durable("consumer1"),
		nats.ManualAck(),
		nats.AckExplicit(),
		nats.BackOff([]time.Duration{50 * time.Millisecond, 250 * time.Millisecond})
	)

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Would add a test and either remove from example or "fix" it as described in the comments.

@derekcollison We (I think I did) added the features (Nak and Backoff) but I simply forgot to add the option. So I think @mfaizanse is just fixing my omission here :-)

example_test.go Outdated
// Start delivering messages with delay based on BackOff array of time durations.
js.Subscribe("foo", func(msg *nats.Msg) {
fmt.Printf("Received a message: %s\n", string(msg.Data))
}, nats.BackOff([]time.Duration{50 * time.Millisecond, 250 * time.Millisecond}))
Copy link
Member

Choose a reason for hiding this comment

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

This complies, but would actually not "work" because you would need to set the MaxDeliver to at least 2 (or more), but also add nats.ManualAck() because otherwise the callback would auto-ack anyway, so it is unlikely that there would be redeliveries...

So instead (or at least in addition to) having this here, I would update, say TestJetStreamSubscribe_AckPolicy test to use the nats.BackOff() new option. In this test (at the end of it), we use backoff but with the AddConsumer directly.

Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM

@kozlovic
Copy link
Member

@derekcollison I have approved this PR, let me know if you still have concerns: we have added the BackOff list consumer configuration in the client, so not sure why is that an issue to make it an option for the js.Subscribe() calls...

@kozlovic kozlovic merged commit 8af932f into nats-io:main Apr 4, 2022
@mfaizanse mfaizanse deleted the backoff_sub_opt branch April 5, 2022 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants