// 注册驱动
funcRegister(namestring,driverdriver.Driver){driversMu.Lock()deferdriversMu.Unlock()ifdriver==nil{panic("sql: Register driver is nil")}if_,dup:=drivers[name];dup{panic("sql: Register called twice for driver "+name)}drivers[name]=driver}// 删除所有注册的驱动
funcunregisterAllDrivers(){driversMu.Lock()deferdriversMu.Unlock()// For tests.
drivers=make(map[string]driver.Driver)}// 当前注册了哪些驱动
// Drivers returns a sorted list of the names of the registered drivers.
funcDrivers()[]string{driversMu.RLock()deferdriversMu.RUnlock()varlist[]stringforname:=rangedrivers{list=append(list,name)}sort.Strings(list)returnlist}
Kafka 是一个非常经典的消息队列,Kafka消费者可以按照消费组的方式进行消费,当多个客户端按照同一个消费组消费消费同一个主题(Topic)的消息时,需要按照一定的策略将客户端与Partition的对应关系协调好,这样多个客户端才能正常消费,这就是Consumer Group 的Reblance。
typeBalanceStrategyinterface{// Name uniquely identifies the strategy.
Name()string// Plan accepts a map of `memberID -> metadata` and a map of `topic -> partitions`
// and returns a distribution plan.
Plan(membersmap[string]ConsumerGroupMemberMetadata,topicsmap[string][]int32)(BalanceStrategyPlan,error)}