-
Notifications
You must be signed in to change notification settings - Fork 339
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
[client] rewrite regexConsumer to avoid duplicate code #848
base: master
Are you sure you want to change the base?
Conversation
c1c811f
to
0e1ccb0
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
pulsar/consumer_regex.go
Outdated
func (c *regexConsumer) topics() ([]string, error) { | ||
topics, err := c.client.lookupService.GetTopicsOfNamespace(c.namespace, internal.Persistent) | ||
func topics(client *client, namespace string, pattern *regexp.Regexp) ([]string, error) { | ||
topics, err := client.lookupService.GetTopicsOfNamespace(namespace, internal.Persistent) |
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.
It should check the client
for nil
.
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.
This is a private function, we ensure the client is not nil. If the client is nil, I think panic is acceptable.
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.
Can we make this function as part of struct method? So that client would not be nil.
func (c *regexConsumer) topics() ..{
topics, err: =c.client
pulsar/consumer_regex.go
Outdated
func (c *regexConsumer) topics() ([]string, error) { | ||
topics, err := c.client.lookupService.GetTopicsOfNamespace(c.namespace, internal.Persistent) | ||
func topics(client *client, namespace string, pattern *regexp.Regexp) ([]string, error) { | ||
topics, err := client.lookupService.GetTopicsOfNamespace(namespace, internal.Persistent) |
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.
Can we make this function as part of struct method? So that client would not be nil.
func (c *regexConsumer) topics() ..{
topics, err: =c.client
pulsar/consumer_regex.go
Outdated
topics, err := topics(client, tn.Namespace, pattern) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mtc, err := newMultiTopicConsumer(client, opts, topics, msgCh, dlq, rlq) | ||
if err != nil { | ||
return nil, err | ||
} |
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.
Can we make this function as part of struct method?
Hi @zzzming. In the original implementation, topics
is a method of regexConsumer
struct. In the new implementation, we need to get the topics before initializing regexConsumer
. But I think make this topics
function as a method of client
struct will be better, I will work on this.
1a51790
to
4e9e33c
Compare
Conflict resolved, ready to merge. |
Ping @labuladong |
Conflict resolved. #805 does the same change in |
Can this pr be merged? @nodece @Gleiphir2769 @RobertIndie |
Fixes #846
Verifying this change
This change is already covered by existing tests, such as
consumer_regex_test.go
.Does this pull request potentially affect one of the following parts:
If
yes
was chosen, please highlight the changesModifications
Reuse
multiTopicConsumer
inregexConsumer
to avoid duplicate code.