// Start a rebalance cycle func (cg *ConsumerGroup) rebalance() (err error) { var cids []string var pids []int32 // Fetch a list of consumers and listen for changes if cids, cg.zkchange, err = cg.zoo.Consumers(cg.name); err != nil { cg.zkchange = nil return } // Fetch a list of partition IDs if pids, err = cg.client.Partitions(cg.topic); err != nil { cg.zkchange = nil return } // Get leaders for each partition ID parts := make(PartitionSlice, len(pids)) for i, pid := range pids { var broker *sarama.Broker if broker, err = cg.client.Leader(cg.topic, pid); err != nil { cg.zkchange = nil return } defer broker.Close() parts[i] = Partition{Id: pid, Addr: broker.Addr()} } if err = cg.makeClaims(cids, parts); err != nil { cg.zkchange = nil cg.releaseClaims() return } return }
func closeBroker(b *sarama.Broker) { if ok, _ := b.Connected(); ok { b.Close() } }