Skip to content

Commit

Permalink
Merge pull request #1983 from zifengyu/master
Browse files Browse the repository at this point in the history
allow configure AllowAutoTopicCreation argument in metadata refresh
  • Loading branch information
dnwe authored Jul 12, 2021
2 parents 0676fc2 + 963906b commit 70416ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func (client *client) tryRefreshMetadata(topics []string, attemptsRemaining int,

broker := client.any()
for ; broker != nil && !pastDeadline(0); broker = client.any() {
allowAutoTopicCreation := true
allowAutoTopicCreation := client.conf.Metadata.AllowAutoTopicCreation
if len(topics) > 0 {
Logger.Printf("client/metadata fetching metadata for %v from broker %s\n", topics, broker.addr)
} else {
Expand Down
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ type Config struct {
// `Net.[Dial|Read]Timeout * BrokerCount * (Metadata.Retry.Max + 1) + Metadata.Retry.Backoff * Metadata.Retry.Max`
// to fail.
Timeout time.Duration

// Whether to allow auto-create topics in metadata refresh. If set to true,
// 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
}

// Producer is the namespace for configuration related to producing messages,
Expand Down Expand Up @@ -456,6 +461,7 @@ func NewConfig() *Config {
c.Metadata.Retry.Backoff = 250 * time.Millisecond
c.Metadata.RefreshFrequency = 10 * time.Minute
c.Metadata.Full = true
c.Metadata.AllowAutoTopicCreation = true

c.Producer.MaxMessageBytes = 1000000
c.Producer.RequiredAcks = WaitForLocal
Expand Down

0 comments on commit 70416ae

Please sign in to comment.