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] Creating iterators for sync subscriptions #1728

Merged
merged 1 commit into from
Dec 17, 2024
Merged

[ADDED] Creating iterators for sync subscriptions #1728

merged 1 commit into from
Dec 17, 2024

Conversation

piotrpio
Copy link
Collaborator

This PR adds iterator capabilities to core NATS subscription. This API extends only to sync subscriptions.

Additionally, this adds an opt-in PermissionErrOnSubscribe option, which (if set) causes sub.NextMsg() to return permission error if encountered. Due to backwards compatibility this option is disabled by default, but we could consider enabling it by default in future releases.

Signed-off-by: Piotr Piotrowski piotr@synadia.com

@piotrpio piotrpio requested review from wallyqs and Jarema October 18, 2024 15:22
@coveralls
Copy link

coveralls commented Oct 18, 2024

Coverage Status

coverage: 84.892% (+0.06%) from 84.836%
when pulling 2ad4e47 on sub-iter
into ee22dc4 on main.

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio marked this pull request as ready for review October 25, 2024 10:06
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

Some questions and clarifications requeted.

return nc.subscribe(subj, _EMPTY_, nil, mch, true, nil)
var errCh chan error
if nc.Opts.PermissionErrOnSubscribe {
errCh = make(chan error, 100)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder what is the proper size for this channel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question, I set it to some value without thinking much about this and kind of forgot to analyze it properly. Since we really only push permission errors on this channel and we do it once per subscription, a buffered channel with size 1 should suffice (so that it's not blocking).

}
subject := matches[1]
for _, sub := range nc.subs {
if sub.Subject == subject && sub.Queue == q && sub.permissionsErr == nil {
Copy link
Member

Choose a reason for hiding this comment

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

sub.Queue would be "" if it's non-queue group subscription, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, so if there is no match for the regex, q will also be "" and it will fulfill this condition.

nats.go Show resolved Hide resolved
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

LGTM

@piotrpio piotrpio merged commit d6eaa84 into main Dec 17, 2024
6 checks passed
@piotrpio piotrpio deleted the sub-iter branch December 17, 2024 14:06
@piotrpio piotrpio mentioned this pull request Dec 17, 2024
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.

3 participants