Skip to content

Commit fb4903e

Browse files
committed
Merge branch 'repr' of https://github.com/mahendra/kafka-python into mahendra-repr
Conflicts: kafka/client.py kafka/consumer.py
2 parents 9644166 + ceee715 commit fb4903e

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

kafka/client.py

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ def _send_broker_aware_request(self, payloads, encoder_fn, decoder_fn):
158158
# Order the accumulated responses by the original key order
159159
return (acc[k] for k in original_keys) if acc else ()
160160

161+
def __repr__(self):
162+
return '<KafkaClient client_id=%s>' % (self.client_id)
163+
161164
def _raise_on_response_error(self, resp):
162165
if resp.error == ErrorMapping.NO_ERROR:
163166
return

kafka/conn.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, host, port, timeout=10):
2828
self._sock.settimeout(self.timeout)
2929
self._dirty = False
3030

31-
def __str__(self):
31+
def __repr__(self):
3232
return "<KafkaConnection host=%s port=%d>" % (self.host, self.port)
3333

3434
###################

kafka/consumer.py

+8
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ def __init__(self, client, group, topic, auto_commit=True, partitions=None,
256256
auto_commit_every_n=auto_commit_every_n,
257257
auto_commit_every_t=auto_commit_every_t)
258258

259+
def __repr__(self):
260+
return '<SimpleConsumer group=%s, topic=%s, partitions=%s>' % \
261+
(self.group, self.topic, str(self.offsets.keys()))
262+
259263
def provide_partition_info(self):
260264
"""
261265
Indicates that partition info must be returned by the consumer
@@ -544,6 +548,10 @@ def __init__(self, client, group, topic, auto_commit=True,
544548
proc.start()
545549
self.procs.append(proc)
546550

551+
def __repr__(self):
552+
return '<MultiProcessConsumer group=%s, topic=%s, consumers=%d>' % \
553+
(self.group, self.topic, len(self.procs))
554+
547555
def stop(self):
548556
# Set exit and start off all waiting consumers
549557
self.exit.set()

kafka/producer.py

+6
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def send_messages(self, *msg):
199199
partition = self.next_partition.next()
200200
return super(SimpleProducer, self).send_messages(partition, *msg)
201201

202+
def __repr__(self):
203+
return '<SimpleProducer topic=%s, batch=%s>' % (self.topic, self.async)
204+
202205

203206
class KeyedProducer(Producer):
204207
"""
@@ -240,3 +243,6 @@ def send(self, key, msg):
240243
partitions = self.client.topic_partitions[self.topic]
241244
partition = self.partitioner.partition(key, partitions)
242245
return self.send_messages(partition, msg)
246+
247+
def __repr__(self):
248+
return '<KeyedProducer topic=%s, batch=%s>' % (self.topic, self.async)

0 commit comments

Comments
 (0)