diff options
author | mrtheb <mrlabbe@gmail.com> | 2014-02-09 13:44:47 -0500 |
---|---|---|
committer | mrtheb <mrlabbe@gmail.com> | 2014-02-09 13:44:47 -0500 |
commit | a2191e5be5d5fcd212582580c163f4533cca6c73 (patch) | |
tree | 6d13a0928f572d99a47299b536cdf209dbd29a5f /kafka/client.py | |
parent | 84de472a4d5b583ff3ed6cc6d92250a7c9291ceb (diff) | |
download | kafka-python-a2191e5be5d5fcd212582580c163f4533cca6c73.tar.gz |
Support list (or comma-separated) of hosts (replaces host and port arguments)
Diffstat (limited to 'kafka/client.py')
-rw-r--r-- | kafka/client.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/kafka/client.py b/kafka/client.py index 33c4419..96cc1df 100644 --- a/kafka/client.py +++ b/kafka/client.py @@ -10,7 +10,7 @@ from kafka.common import (ErrorMapping, TopicAndPartition, BrokerResponseError, PartitionUnavailableError, KafkaUnavailableError, KafkaRequestError) -from kafka.conn import KafkaConnection, DEFAULT_SOCKET_TIMEOUT_SECONDS +from kafka.conn import collect_hosts, KafkaConnection, DEFAULT_SOCKET_TIMEOUT_SECONDS from kafka.protocol import KafkaProtocol log = logging.getLogger("kafka") @@ -24,14 +24,15 @@ class KafkaClient(object): # NOTE: The timeout given to the client should always be greater than the # one passed to SimpleConsumer.get_message(), otherwise you can get a # socket timeout. - def __init__(self, host, port, client_id=CLIENT_ID, + def __init__(self, hosts, client_id=CLIENT_ID, timeout=DEFAULT_SOCKET_TIMEOUT_SECONDS): # We need one connection to bootstrap self.client_id = client_id self.timeout = timeout - self.conns = { # (host, port) -> KafkaConnection - (host, port): KafkaConnection(host, port, timeout=timeout) - } + self.hosts = collect_hosts(hosts) + + # create connections only when we need them + self.conns = {} self.brokers = {} # broker_id -> BrokerMetadata self.topics_to_brokers = {} # topic_id -> broker_id self.topic_partitions = {} # topic_id -> [0, 1, 2, ...] @@ -46,7 +47,7 @@ class KafkaClient(object): host_key = (host, port) if host_key not in self.conns: - self.conns[host_key] = KafkaConnection(host, port, self.bufsize) + self.conns[host_key] = KafkaConnection(host, port) return self.conns[host_key] |