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
Make Durable mandatory for PullSubscribe #691
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
func (js *js) PullSubscribe(subj string, opts ...SubOpt) (*Subscription, error) { | ||
return js.subscribe(subj, _EMPTY_, nil, nil, opts) | ||
func (js *js) PullSubscribe(subj, durable string, opts ...SubOpt) (*Subscription, error) { | ||
return js.subscribe(subj, _EMPTY_, nil, nil, append(opts, Durable(durable))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we prevent here that nats.Durable is passed so that it is not ambiguous?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, yeah. Good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated nats.Durable
to check if it has already been set. If so, it returns an error.
func Durable(name string) SubOpt {
return subOptFn(func(opts *subOpts) error {
if opts.cfg.Durable != "" {
return fmt.Errorf("nats: option Durable set more than once")
}
if strings.Contains(name, ".") {
return ErrInvalidDurableName
}
opts.cfg.Durable = name
return nil
})
}
I also added this new test code.
sub, err = js.PullSubscribe("bar", "foo", nats.Durable("bar"))
if err == nil {
t.Fatalf("Unexpected success")
}
if err != nil && err.Error() != `nats: option Durable set more than once` {
t.Errorf("Expected consumer in pull mode error, got %v", err)
}
nats.Durable is a SubOpt that may be passed to PullSubscribe or other methods. If a durable name isn't passed to PullSubscribe, then we return a runtime error. Instead of returning a runtime error for this case, this change updates the PullSubscribe method to require a durable name parameter.
c2a8114
to
077cf10
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
nats.Durable is a SubOpt that may be passed to PullSubscribe or other
methods. If a durable name isn't passed to PullSubscribe, then we return
a runtime error.
Instead of returning a runtime error for this case, this change updates
the PullSubscribe method to require a durable name parameter.