Skip to content

Commit

Permalink
allow a client id to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Lim committed Sep 26, 2013
1 parent 4ea2954 commit b477fc2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions kafka/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class KafkaClient(object):
CLIENT_ID = "kafka-python"
ID_GEN = count()

def __init__(self, host, port, bufsize=4096):
def __init__(self, host, port, bufsize=4096, client_id=CLIENT_ID):
# We need one connection to bootstrap
self.bufsize = bufsize
self.bufsize = bufsize
self.client_id = client_id
self.conns = { # (host, port) -> KafkaConnection
(host, port): KafkaConnection(host, port, bufsize)
}
Expand Down Expand Up @@ -59,7 +60,7 @@ def _load_metadata_for_topics(self, *topics):
recurse in the event of a retry.
"""
requestId = self._next_id()
request = KafkaProtocol.encode_metadata_request(KafkaClient.CLIENT_ID,
request = KafkaProtocol.encode_metadata_request(self.client_id,
requestId, topics)

response = self._send_broker_unaware_request(requestId, request)
Expand Down Expand Up @@ -156,7 +157,7 @@ def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn):
for broker, payloads in payloads_by_broker.items():
conn = self._get_conn_for_broker(broker)
requestId = self._next_id()
request = encoder_fn(client_id=KafkaClient.CLIENT_ID,
request = encoder_fn(client_id=self.client_id,
correlation_id=requestId, payloads=payloads)

# Send the request, recv the response
Expand Down

0 comments on commit b477fc2

Please sign in to comment.