|
@@ -8,8 +8,9 @@ import (
|
|
|
|
|
|
|
|
|
|
type ClientConfig struct {
|
|
type ClientConfig struct {
|
|
- MetadataRetries int
|
|
+ MetadataRetries int
|
|
- WaitForElection time.Duration
|
|
+ WaitForElection time.Duration
|
|
|
|
+ ConcurrencyPerBroker int
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -43,6 +44,10 @@ func NewClient(id string, addrs []string, config *ClientConfig) (*Client, error)
|
|
return nil, ConfigurationError("Invalid MetadataRetries")
|
|
return nil, ConfigurationError("Invalid MetadataRetries")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if config.ConcurrencyPerBroker < 0 {
|
|
|
|
+ return nil, ConfigurationError("Invalid ConcurrencyPerBroker")
|
|
|
|
+ }
|
|
|
|
+
|
|
if len(addrs) < 1 {
|
|
if len(addrs) < 1 {
|
|
return nil, ConfigurationError("You must provide at least one broker address")
|
|
return nil, ConfigurationError("You must provide at least one broker address")
|
|
}
|
|
}
|
|
@@ -55,7 +60,7 @@ func NewClient(id string, addrs []string, config *ClientConfig) (*Client, error)
|
|
brokers: make(map[int32]*Broker),
|
|
brokers: make(map[int32]*Broker),
|
|
leaders: make(map[string]map[int32]int32),
|
|
leaders: make(map[string]map[int32]int32),
|
|
}
|
|
}
|
|
- client.extraBroker.Open()
|
|
+ client.extraBroker.Open(config.ConcurrencyPerBroker)
|
|
|
|
|
|
|
|
|
|
err := client.RefreshAllMetadata()
|
|
err := client.RefreshAllMetadata()
|
|
@@ -165,7 +170,7 @@ func (client *Client) disconnectBroker(broker *Broker) {
|
|
client.extraBrokerAddrs = client.extraBrokerAddrs[1:]
|
|
client.extraBrokerAddrs = client.extraBrokerAddrs[1:]
|
|
if len(client.extraBrokerAddrs) > 0 {
|
|
if len(client.extraBrokerAddrs) > 0 {
|
|
client.extraBroker = NewBroker(client.extraBrokerAddrs[0])
|
|
client.extraBroker = NewBroker(client.extraBrokerAddrs[0])
|
|
- client.extraBroker.Open()
|
|
+ client.extraBroker.Open(client.config.ConcurrencyPerBroker)
|
|
} else {
|
|
} else {
|
|
client.extraBroker = nil
|
|
client.extraBroker = nil
|
|
}
|
|
}
|
|
@@ -268,12 +273,12 @@ func (client *Client) update(data *MetadataResponse) ([]string, error) {
|
|
|
|
|
|
for _, broker := range data.Brokers {
|
|
for _, broker := range data.Brokers {
|
|
if client.brokers[broker.ID()] == nil {
|
|
if client.brokers[broker.ID()] == nil {
|
|
- broker.Open()
|
|
+ broker.Open(client.config.ConcurrencyPerBroker)
|
|
client.brokers[broker.ID()] = broker
|
|
client.brokers[broker.ID()] = broker
|
|
Logger.Printf("Registered new broker #%d at %s", broker.ID(), broker.Addr())
|
|
Logger.Printf("Registered new broker #%d at %s", broker.ID(), broker.Addr())
|
|
} else if broker.Addr() != client.brokers[broker.ID()].Addr() {
|
|
} else if broker.Addr() != client.brokers[broker.ID()].Addr() {
|
|
go client.brokers[broker.ID()].Close()
|
|
go client.brokers[broker.ID()].Close()
|
|
- broker.Open()
|
|
+ broker.Open(client.config.ConcurrencyPerBroker)
|
|
client.brokers[broker.ID()] = broker
|
|
client.brokers[broker.ID()] = broker
|
|
Logger.Printf("Replaced registered broker #%d with %s", broker.ID(), broker.Addr())
|
|
Logger.Printf("Replaced registered broker #%d with %s", broker.ID(), broker.Addr())
|
|
}
|
|
}
|