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

[client] rewrite regexConsumer to avoid duplicate code #848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

labuladong
Copy link
Contributor

@labuladong labuladong commented Sep 16, 2022

Fixes #846

Verifying this change

  • Make sure that the change passes the CI checks.

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 changes

  • The public API: (yes)
  • The schema: (don't know)
  • The default values of configurations: (no)
  • The wire protocol: (no)

Modifications

Reuse multiTopicConsumer in regexConsumer to avoid duplicate code.

@labuladong
Copy link
Contributor Author

cc @nodece @RobertIndie @wolfstudy

@labuladong labuladong changed the title [client] rewrite regexConsumer and fix unit test [client] rewrite regexConsumer to avoid duplicate code Sep 19, 2022
@nodece nodece self-requested a review September 19, 2022 03:20
Copy link
Member

@nodece nodece left a comment

Choose a reason for hiding this comment

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

LGTM

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

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)
Copy link
Contributor

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

Comment on lines 51 to 58
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
}
Copy link
Contributor Author

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.

@labuladong
Copy link
Contributor Author

labuladong commented Oct 11, 2022

Conflict resolved, ready to merge.

@nodece
Copy link
Member

nodece commented Nov 29, 2022

Ping @labuladong

@labuladong
Copy link
Contributor Author

Conflict resolved. #805 does the same change in regexConsumer and multiTopicConsumer, so this PR is still compatible.

@labuladong
Copy link
Contributor Author

Can this pr be merged? @nodece @Gleiphir2769 @RobertIndie

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.

Suggest rewrite regexConsumer with inheritance
5 participants