Skip to content

Commit

Permalink
make topics as method of client
Browse files Browse the repository at this point in the history
  • Loading branch information
labuladong committed Oct 11, 2022
1 parent df8a2d1 commit 4e9e33c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 11 additions & 0 deletions pulsar/client_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package pulsar
import (
"fmt"
"net/url"
"regexp"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -229,3 +230,13 @@ func (c *client) Close() {
c.cnxPool.Close()
c.lookupService.Close()
}

func (c *client) topics(namespace string, pattern *regexp.Regexp) ([]string, error) {
topics, err := c.lookupService.GetTopicsOfNamespace(namespace, internal.Persistent)
if err != nil {
return nil, err
}

filtered := filterTopics(topics, pattern)
return filtered, nil
}
14 changes: 2 additions & 12 deletions pulsar/consumer_regex.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type regexConsumer struct {

func newRegexConsumer(client *client, opts ConsumerOptions, tn *internal.TopicName, pattern *regexp.Regexp,
msgCh chan ConsumerMessage, dlq *dlqRouter, rlq *retryRouter) (*regexConsumer, error) {
topics, err := topics(client, tn.Namespace, pattern)
topics, err := client.topics(tn.Namespace, pattern)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -160,7 +160,7 @@ func (c *regexConsumer) monitor() {
}

func (c *regexConsumer) discover() {
topics, err := topics(c.client, c.namespace, c.pattern)
topics, err := c.client.topics(c.namespace, c.pattern)
if err != nil {
c.log.WithError(err).Errorf("Failed to discover topics")
return
Expand Down Expand Up @@ -235,16 +235,6 @@ func (c *regexConsumer) unsubscribe(topics []string) {
}
}

func topics(client *client, namespace string, pattern *regexp.Regexp) ([]string, error) {
topics, err := client.lookupService.GetTopicsOfNamespace(namespace, internal.Persistent)
if err != nil {
return nil, err
}

filtered := filterTopics(topics, pattern)
return filtered, nil
}

type consumerError struct {
err error
topic string
Expand Down

0 comments on commit 4e9e33c

Please sign in to comment.