本文整理匯總了Golang中github.com/Shopify/sarama.Broker.Close方法的典型用法代碼示例。如果您正苦於以下問題:Golang Broker.Close方法的具體用法?Golang Broker.Close怎麽用?Golang Broker.Close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Shopify/sarama.Broker
的用法示例。
在下文中一共展示了Broker.Close方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: rebalance
// 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
}
示例2: closeBroker
func closeBroker(b *sarama.Broker) {
if ok, _ := b.Connected(); ok {
b.Close()
}
}