Skip to content

Commit

Permalink
Merge pull request #813 from hollow/get_brokers
Browse files Browse the repository at this point in the history
make list of brokers available through sarama.Client
  • Loading branch information
eapache authored Jan 27, 2017
2 parents 30a4aff + b9842b6 commit 574d314
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Client interface {
// altered after it has been created.
Config() *Config

// Brokers returns the current set of active brokers as retrieved from cluster metadata.
Brokers() []*Broker

// Topics returns the set of available topics as retrieved from cluster metadata.
Topics() ([]string, error)

Expand Down Expand Up @@ -157,6 +160,16 @@ func (client *client) Config() *Config {
return client.conf
}

func (client *client) Brokers() []*Broker {
client.lock.RLock()
defer client.lock.RUnlock()
brokers := make([]*Broker, 0)
for _, broker := range client.brokers {
brokers = append(brokers, broker)
}
return brokers
}

func (client *client) Close() error {
if client.Closed() {
// Chances are this is being called from a defer() and the error will go unobserved
Expand Down

0 comments on commit 574d314

Please sign in to comment.