Skip to content

Commit

Permalink
fix metadata disable full scan
Browse files Browse the repository at this point in the history
  • Loading branch information
famarting committed Mar 11, 2024
1 parent f21c512 commit e7dedc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ func NewClient(addrs []string, conf *Config) (Client, error) {

client.randomizeSeedBrokers(addrs)

for _, t := range conf.Metadata.InitialTopics {
client.metadataTopics[t] = none{}
}

if conf.Metadata.Full {
// do an initial fetch of all cluster metadata by specifying an empty list of topics
err := client.RefreshMetadata()
// do an initial fetch of cluster metadata
err := client.RefreshMetadata(conf.Metadata.InitialTopics...)
if err == nil {
} else if errors.Is(err, ErrLeaderNotAvailable) || errors.Is(err, ErrReplicaNotAvailable) || errors.Is(err, ErrTopicAuthorizationFailed) || errors.Is(err, ErrClusterAuthorizationFailed) {
// indicates that maybe part of the cluster is down, but is not fatal to creating the client
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ type Config struct {
// the broker may auto-create topics that we requested which do not already exist,
// if it is configured to do so (`auto.create.topics.enable` is true). Defaults to true.
AllowAutoTopicCreation bool

// Optional set of topics whose metadata will be fetched at startup. If empty it will default
// to fetch the metadata for all topics
InitialTopics []string
}

// Producer is the namespace for configuration related to producing messages,
Expand Down

0 comments on commit e7dedc5

Please sign in to comment.