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 ability to use PullConsumers with NATS jetstream with a specified callback #1075

Conversation

stephen-totty-hpe
Copy link
Contributor

In many cases, the reciever of a message might want some ability to exercise control over the fetching. Also, with NATS, there are options inside the NATS server that might be beneficial to use a pull-based consumer.

@stephen-totty-hpe stephen-totty-hpe requested a review from a team as a code owner July 9, 2024 14:37
Comment on lines 183 to 204
if err != nil || msgs == nil {
continue
}

Choose a reason for hiding this comment

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

Not sure I'm a fan of just dropping the error message here, unless it is logged internall before it is called?

Also there's no need for the nil check on msgs - range over a nil slice is a valid operation and just skips.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

returning error to calling function.

continue
}
for i := range msgs {
msg := msgs[i]

Choose a reason for hiding this comment

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

I don't think an assignment is needed here given MsgHandler is synchonous?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed assignment

@stephen-totty-hpe stephen-totty-hpe force-pushed the totty/nats-pull-consumer-2024 branch 2 times, most recently from 9212db4 to bd93dc5 Compare July 15, 2024 20:10
Copy link
Member

@embano1 embano1 left a comment

Choose a reason for hiding this comment

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

I'm not a NATS expert, but IMHO this PR is using a legacy API:

// NOTE: JetStream is part of legacy API.
// Users are encouraged to switch to the new JetStream API for enhanced capabilities and
// simplified API. Please refer to the jetstream package.
// See: https://github.com/nats-io/nats.go/blob/main/jetstream/README.md

I like the idea of pull-based subscriptions to give more control, but IMHO we should switch to the newer API and clean up the whole code base of this implementation to avoid setting up both, push and pull-based consumers. This can also simplify the current proposal, removing having two similar for select implementations as proposed in this PR.

@stephen-totty-hpe
Copy link
Contributor Author

I'm not a NATS expert, but IMHO this PR is using a legacy API:

// NOTE: JetStream is part of legacy API.
// Users are encouraged to switch to the new JetStream API for enhanced capabilities and
// simplified API. Please refer to the jetstream package.
// See: https://github.com/nats-io/nats.go/blob/main/jetstream/README.md

I like the idea of pull-based subscriptions to give more control, but IMHO we should switch to the newer API and clean up the whole code base of this implementation to avoid setting up both, push and pull-based consumers. This can also simplify the current proposal, removing having two similar for select implementations as proposed in this PR.

@embano1 Using the new api is a good idea. The old api was already in use and it seemed I would have to version the library because many of the exposed options are different. Or I would have to do some hacky translation of the old option to the new option. There are several slight issues I have with the current implementation that I believe using the new api might benefit.
If I was to write a new version, I assume it would be at:
protocol/nats_jetstream/v3 ?

@embano1
Copy link
Member

embano1 commented Jul 28, 2024

If I was to write a new version, I assume it would be at:
protocol/nats_jetstream/v3 ?

Do you think it would be possible to use the new NATS API/library without breaking CloudEvents users? We're currently doing a similar migration in AMQP and while we're still discussing how to avoid small breaking changes (there might be some, but minor), I think we could do the same with NATS incrementally and not break users?

@duglin
Copy link
Contributor

duglin commented Sep 26, 2024

@stephen-totty-hpe ping

@duglin duglin force-pushed the totty/nats-pull-consumer-2024 branch from bd93dc5 to 46f3bf8 Compare September 26, 2024 14:11
@stephen-totty-hpe
Copy link
Contributor Author

@stephen-totty-hpe ping

I will close this PR if #1095 gets merged.

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