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

Alias NextMsg to Fetch for Pull Subscribers #754

Closed
wants to merge 3 commits into from

Conversation

Jarema
Copy link
Member

@Jarema Jarema commented Jun 19, 2021

Addresses #747

@coveralls
Copy link

coveralls commented Jun 19, 2021

Coverage Status

Coverage decreased (-0.03%) to 86.804% when pulling dad4664 on Jarema:master into cc4f3b2 on nats-io:master.

@Jarema
Copy link
Member Author

Jarema commented Jun 19, 2021

I tried to make changes in the test as little and not-confusing as possible. Let me know if it's good enough.

@Jarema Jarema force-pushed the master branch 3 times, most recently from 7339f63 to 4605b8d Compare June 19, 2021 19:16
@derekcollison
Copy link
Member

Thanks will take a look!

@wallyqs
Copy link
Member

wallyqs commented Aug 3, 2021

Based on user feedback and issues such as #785 it seems that might help to make NextMsg() become an alias to Fetch(1), wdyt? @ColinSullivan1 @kozlovic @scottf

@kozlovic
Copy link
Member

kozlovic commented Aug 3, 2021

@wallyqs Except that with Fetch() you could pass options that you can't with NextMsg(). Maybe it is better to fail for pull subscriptions (what I do in C), to make it clear that this is not a regular sync subscription. But I could be convinced otherwise.

@wallyqs
Copy link
Member

wallyqs commented Aug 3, 2021

But the options for Fetch are only timeout related (MaxWait for a timeout or a Context) so might be fine, though as you mention it could be that we should just fail in case NextMsg is attempted to be used instead of just timing out.

@kozlovic
Copy link
Member

kozlovic commented Aug 3, 2021

@wallyqs Well, in the C client, and maybe the Go client if we update the implementation, the pull subscription will use a sync subscription, so in a way I prevent the user from calling NextMsg(), since i use that internally by sending MSG.NEXT request with the reply subject of the sync sub was created on. The difference is that Fetch() is going to "filter out" the status messages possibly sent by the server.

Now, I realize that I am mudding things up: if the intent is to have NextMsg() for a pull subscribe to basically do:

   msgs, err := sub.Fetch(1)
   if err != nil {
      return nil, err
   }
   return msgs[0], nil

then I guess I am fine with that.

@scottf
Copy link
Contributor

scottf commented Aug 4, 2021

I'm against conflating NextMsg and Fetch. Also, Fetch is a "macro" that sets up a pull and does the NextMsg for the user. All 3 varieties of pull require the user to call NextMsg. It seems to me that this concept is getting lost

@kszafran
Copy link

kszafran commented Aug 14, 2021

I just spend some time myself scratching my head trying to figure out why NextMsg didn't read any messages (I was using a pull subscriber).

How about instead of aliasing it to Fetch we panic with a message like "use Fetch instead of NextMsg to fetch messages with a pull consumer"? It will also solve the problem with confused newcomers (like me), but it'll make sure that there's only one way to fetch messages with a pull subscriber, not two. IMO aliasing to Fetch does not solve anything that panic wouldn't solve, but it might make code maintenance more difficult in the future (for both the library maintainers and library users).

@kozlovic
Copy link
Member

I apologize for the delay but we have decided to make calling NextMsg() on a pull subscription an error (you need to call Fetch). The error will be ErrTypeSubscription. This will be part of an upcoming PR since we have lot of planned changes for JetStream. The PR should be up today/tomorrow or Monday at the latest. So I am closing this PR.

@kozlovic kozlovic closed this Aug 14, 2021
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

7 participants