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] PushConsumer implementation in jetstream package #1785

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

piotrpio
Copy link
Collaborator

This PR introduces a PushConsumer implementation in jetstream API. For now it only exposes callback-based Consume() implementation.
Due to interface differences and breaking change concerns, a completely new set of methods were added to enable operating on push consumers.

Signed-off-by: Piotr Piotrowski [email protected]

@piotrpio piotrpio force-pushed the js-simplification-push-consumer branch from dd63422 to ff230a4 Compare January 22, 2025 21:34
@coveralls
Copy link

coveralls commented Jan 22, 2025

Coverage Status

coverage: 85.095% (+0.2%) from 84.911%
when pulling 05b9311 on js-simplification-push-consumer
into f7dfee9 on main.

@alexbozhenko
Copy link
Contributor

@piotrpio
https://docs.nats.io/using-nats/developer/develop_jetstream/consumers#pull-consumers says:

We recommend using pull consumers for new projects. In particular when scalability, detailed flow control or error handling are a design focus. Most client API have been updated to provide convenient interfaces for consuming messages through callback handler or iterators without the need to manage message retrieval.

Since we are adding push consumers to the new package, I guess the statement above is not true, and should be updated?

@Jarema
Copy link
Member

Jarema commented Jan 22, 2025

No @alexbozhenko , the statement still holds.

We still recommend using pull consumers.
We're just adding support for push so people can migrate to the new api without migrating every consumer, plus to support some niche cases where it can still make sense.

@piotrpio
Copy link
Collaborator Author

@alexbozhenko I don't think so - pull consumers are still the recommended way to go, we only want to provide an option to use push consumers as:
a) users may want to switch to jetstream package but are already using push consumers
b) in some scenarios, using push consumers can be a good idea

@piotrpio piotrpio force-pushed the js-simplification-push-consumer branch from ff230a4 to 2b329b3 Compare January 23, 2025 12:13
@piotrpio piotrpio force-pushed the js-simplification-push-consumer branch 4 times, most recently from 5e10998 to b19500d Compare January 23, 2025 13:43
Signed-off-by: Piotr Piotrowski <[email protected]>
@piotrpio piotrpio force-pushed the js-simplification-push-consumer branch from b19500d to 7a59b11 Compare January 23, 2025 13:46
// PushConsumeOpt options:
//
// - Error handling and monitoring can be configured using ConsumeErrHandler.
Consume(handler MessageHandler, opts ...PushConsumeOpt) (ConsumeContext, error)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to provide the Messages variant with Next? Was it available in old JS? Can't recall.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It kind of was, via ChanSubscribe and yes, I think we should add that API, but I would do it in a separate PR.

jetstream/jetstream.go Outdated Show resolved Hide resolved
// CreateOrUpdateConsumer creates a push consumer on a given stream with
// given config. If consumer already exists, it will be updated (if
// possible). Consumer interface is returned, allowing to operate on a
// consumer (e.g. fetch messages).
Copy link
Member

Choose a reason for hiding this comment

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

e.g. fetch messages is not a best example here ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, changed to "allowing to consume messages"

jetstream/jetstream.go Outdated Show resolved Hide resolved
jetstream/jetstream.go Outdated Show resolved Hide resolved
jetstream/stream.go Outdated Show resolved Hide resolved
jetstream/stream.go Outdated Show resolved Hide resolved
jetstream/stream.go Outdated Show resolved Hide resolved
jetstream/stream.go Outdated Show resolved Hide resolved
jetstream/stream.go Outdated Show resolved Hide resolved
piotrpio and others added 3 commits January 29, 2025 20:24
Co-authored-by: Tomasz Pietrek <[email protected]>
Signed-off-by: Piotr Piotrowski <[email protected]>
@piotrpio piotrpio force-pushed the js-simplification-push-consumer branch from 4c6dd19 to 6a540ca Compare January 29, 2025 19:36
Signed-off-by: Piotr Piotrowski <[email protected]>
@piotrpio piotrpio requested a review from Jarema January 30, 2025 12:29
@piotrpio piotrpio marked this pull request as ready for review January 30, 2025 12:29
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.

4 participants