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

Implement Consumers Pause #1093

Merged
merged 12 commits into from
Mar 7, 2024
Merged

Implement Consumers Pause #1093

merged 12 commits into from
Mar 7, 2024

Conversation

MauriceVanVeen
Copy link
Member

@MauriceVanVeen MauriceVanVeen commented Mar 2, 2024

Resolves #1084

Adds support for pausing and resuming consumers.

  • The JetStreamManagement now has methods to jsm.pauseConsumer(stream, consumer, pauseUntil), as well as jsm.resumeConsumer(stream, consumer).
  • An example for the above is also added to src/examples.
  • ConsumerConfiguration/builder now has support for setting pauseUntil as well. Allowing to set it during consumer creation.

An optional addition (not implemented now) could be:

  • Not allowing pause/resume when not running the appropriate server version. Throwing a custom exception, instead of a timeout (since the server is not listening to the subjects). What do you think?

@MauriceVanVeen
Copy link
Member Author

MauriceVanVeen commented Mar 2, 2024

Waiting for a fix to nats-io/nats-server#5163. Currently fails the consumer info check that's been added in the last commit.

EDIT: Fix has been merged, the tests now pass 🎉

Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

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

Looks great, just some minor changes. Also can you add this to the example:


// 8. Try to pause a consumer that does not exist and you will get an exception
System.out.println("\n----------\n8. Pause non-existent consumer .");
try
{
    jsm.pauseConsumer(exArgs.stream, durable1, ZonedDateTime.now());
}
catch (JetStreamApiException e)
{
    System.out.println("Exception was: '" + e.getMessage() + "'");
}

* server such as timeout or interruption
* @throws JetStreamApiException the request had an error related to the data, for instance the consumer does not exist.
*/
ConsumerPauseResponse pauseConsumer(String streamName, String consumerName, ZonedDateTime pauseUntil) throws IOException, JetStreamApiException;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there should be two api here, one that does not take pauseUntil, since it is not required.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean having three methods in the end:

  • pauseConsumer(streamName, consumerName, pauseUntil)
  • pauseConsumer(streamName, consumerName)
  • resumeConsumer(streamName, consumerName)

When not sending a pauseUntil, the consumer does not get paused and should be equivalent to calling resumeConsumer instead. So pauseConsumer is used to pause a consumer until the set date, and resumeConsumer resumes it. Could you explain why you'd expect two api here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I thought no pauseUntil meant pause until resume. So just ignore this comment.

"pauseUntil='" + pauseUntil + "'" +
'}';
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a test for this, otherwise coverage goes down. Usually I just assign it and do something like contains("true"). Or just remove it since someone could call toJson

Copy link
Member Author

Choose a reason for hiding this comment

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

Have removed it

Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

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

LGTM

@scottf scottf merged commit 6c5ae3f into main Mar 7, 2024
2 checks passed
@scottf scottf deleted the feat/consumer-pause-resume branch March 7, 2024 18:48
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.

Implement Consumers Pause
2 participants