Skip to content

Commit 9af7b81

Browse files
committed
Merge pull request dpkp#45 from quixey/allow-client-id
Allow a client id to be passed to the client +1 thanks, @jimjh
2 parents 0c732ca + caf7c68 commit 9af7b81

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kafka/client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class KafkaClient(object):
2020
CLIENT_ID = "kafka-python"
2121
ID_GEN = count()
2222

23-
def __init__(self, host, port, bufsize=4096):
23+
def __init__(self, host, port, bufsize=4096, client_id=CLIENT_ID):
2424
# We need one connection to bootstrap
25-
self.bufsize = bufsize
25+
self.bufsize = bufsize
26+
self.client_id = client_id
2627
self.conns = { # (host, port) -> KafkaConnection
2728
(host, port): KafkaConnection(host, port, bufsize)
2829
}
@@ -59,7 +60,7 @@ def _load_metadata_for_topics(self, *topics):
5960
recurse in the event of a retry.
6061
"""
6162
requestId = self._next_id()
62-
request = KafkaProtocol.encode_metadata_request(KafkaClient.CLIENT_ID,
63+
request = KafkaProtocol.encode_metadata_request(self.client_id,
6364
requestId, topics)
6465

6566
response = self._send_broker_unaware_request(requestId, request)
@@ -156,7 +157,7 @@ def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn):
156157
for broker, payloads in payloads_by_broker.items():
157158
conn = self._get_conn_for_broker(broker)
158159
requestId = self._next_id()
159-
request = encoder_fn(client_id=KafkaClient.CLIENT_ID,
160+
request = encoder_fn(client_id=self.client_id,
160161
correlation_id=requestId, payloads=payloads)
161162

162163
# Send the request, recv the response

0 commit comments

Comments
 (0)