@@ -35,7 +35,8 @@ class KafkaConsumer(six.Iterator):
35
35
36
36
Arguments:
37
37
*topics (str): optional list of topics to subscribe to. If not set,
38
- call :meth:`.subscribe` or :meth:`.assign` before consuming records.
38
+ call :meth:`~kafka.KafkaConsumer.subscribe` or
39
+ :meth:`~kafka.KafkaConsumer.assign` before consuming records.
39
40
40
41
Keyword Arguments:
41
42
bootstrap_servers: 'host[:port]' string (or list of 'host[:port]'
@@ -127,7 +128,7 @@ class KafkaConsumer(six.Iterator):
127
128
session_timeout_ms (int): The timeout used to detect failures when
128
129
using Kafka's group management facilities. Default: 30000
129
130
max_poll_records (int): The maximum number of records returned in a
130
- single call to :meth:`.poll`. Default: 500
131
+ single call to :meth:`~kafka.KafkaConsumer .poll`. Default: 500
131
132
receive_buffer_bytes (int): The size of the TCP receive buffer
132
133
(SO_RCVBUF) to use when reading data. Default: None (relies on
133
134
system defaults). The java client defaults to 32768.
@@ -172,6 +173,7 @@ class KafkaConsumer(six.Iterator):
172
173
api_version (tuple): Specify which Kafka API version to use. If set to
173
174
None, the client will attempt to infer the broker version by probing
174
175
various APIs. Different versions enable different functionality.
176
+
175
177
Examples:
176
178
(0, 9) enables full group coordination features with automatic
177
179
partition assignment and rebalancing,
@@ -181,6 +183,7 @@ class KafkaConsumer(six.Iterator):
181
183
partition assignment only,
182
184
(0, 8, 0) enables basic functionality but requires manual
183
185
partition assignment and offset management.
186
+
184
187
For the full list of supported versions, see
185
188
KafkaClient.API_VERSIONS. Default: None
186
189
api_version_auto_timeout_ms (int): number of milliseconds to throw a
@@ -336,11 +339,13 @@ def assign(self, partitions):
336
339
partitions (list of TopicPartition): Assignment for this instance.
337
340
338
341
Raises:
339
- IllegalStateError: If consumer has already called :meth:`.subscribe`.
342
+ IllegalStateError: If consumer has already called
343
+ :meth:`~kafka.KafkaConsumer.subscribe`.
340
344
341
345
Warning:
342
346
It is not possible to use both manual partition assignment with
343
- :meth:`.assign` and group assignment with :meth:`.subscribe`.
347
+ :meth:`~kafka.KafkaConsumer.assign` and group assignment with
348
+ :meth:`~kafka.KafkaConsumer.subscribe`.
344
349
345
350
Note:
346
351
This interface does not support incremental assignment and will
@@ -358,12 +363,13 @@ def assign(self, partitions):
358
363
def assignment (self ):
359
364
"""Get the TopicPartitions currently assigned to this consumer.
360
365
361
- If partitions were directly assigned using :meth:`.assign`, then this
362
- will simply return the same partitions that were previously assigned.
363
- If topics were subscribed using :meth:`.subscribe`, then this will give
364
- the set of topic partitions currently assigned to the consumer (which
365
- may be None if the assignment hasn't happened yet, or if the partitions
366
- are in the process of being reassigned).
366
+ If partitions were directly assigned using
367
+ :meth:`~kafka.KafkaConsumer.assign`, then this will simply return the
368
+ same partitions that were previously assigned. If topics were
369
+ subscribed using :meth:`~kafka.KafkaConsumer.subscribe`, then this will
370
+ give the set of topic partitions currently assigned to the consumer
371
+ (which may be None if the assignment hasn't happened yet, or if the
372
+ partitions are in the process of being reassigned).
367
373
368
374
Returns:
369
375
set: {TopicPartition, ...}
@@ -527,8 +533,8 @@ def poll(self, timeout_ms=0, max_records=None):
527
533
with any records that are available currently in the buffer,
528
534
else returns empty. Must not be negative. Default: 0
529
535
max_records (int, optional): The maximum number of records returned
530
- in a single call to :meth:`. poll`. Default: Inherit value from
531
- max_poll_records.
536
+ in a single call to :meth:`~kafka.KafkaConsumer. poll`.
537
+ Default: Inherit value from max_poll_records.
532
538
533
539
Returns:
534
540
dict: Topic to list of records since the last fetch for the
@@ -639,10 +645,12 @@ def highwater(self, partition):
639
645
def pause (self , * partitions ):
640
646
"""Suspend fetching from the requested partitions.
641
647
642
- Future calls to :meth:`.poll` will not return any records from these
643
- partitions until they have been resumed using :meth:`.resume`. Note that
644
- this method does not affect partition subscription. In particular, it
645
- does not cause a group rebalance when automatic assignment is used.
648
+ Future calls to :meth:`~kafka.KafkaConsumer.poll` will not return any
649
+ records from these partitions until they have been resumed using
650
+ :meth:`~kafka.KafkaConsumer.resume`.
651
+
652
+ Note: This method does not affect partition subscription. In particular,
653
+ it does not cause a group rebalance when automatic assignment is used.
646
654
647
655
Arguments:
648
656
*partitions (TopicPartition): Partitions to pause.
@@ -654,7 +662,8 @@ def pause(self, *partitions):
654
662
self ._subscription .pause (partition )
655
663
656
664
def paused (self ):
657
- """Get the partitions that were previously paused using :meth:`.pause`.
665
+ """Get the partitions that were previously paused using
666
+ :meth:`~kafka.KafkaConsumer.pause`.
658
667
659
668
Returns:
660
669
set: {partition (TopicPartition), ...}
@@ -677,10 +686,12 @@ def seek(self, partition, offset):
677
686
"""Manually specify the fetch offset for a TopicPartition.
678
687
679
688
Overrides the fetch offsets that the consumer will use on the next
680
- :meth:`.poll`. If this API is invoked for the same partition more than
681
- once, the latest offset will be used on the next :meth:`.poll`. Note
682
- that you may lose data if this API is arbitrarily used in the middle of
683
- consumption, to reset the fetch offsets.
689
+ :meth:`~kafka.KafkaConsumer.poll`. If this API is invoked for the same
690
+ partition more than once, the latest offset will be used on the next
691
+ :meth:`~kafka.KafkaConsumer.poll`.
692
+
693
+ Note: You may lose data if this API is arbitrarily used in the middle of
694
+ consumption to reset the fetch offsets.
684
695
685
696
Arguments:
686
697
partition (TopicPartition): Partition for seek operation
@@ -752,7 +763,7 @@ def subscribe(self, topics=(), pattern=None, listener=None):
752
763
Topic subscriptions are not incremental: this list will replace the
753
764
current assignment (if there is one).
754
765
755
- This method is incompatible with :meth:`.assign`.
766
+ This method is incompatible with :meth:`~kafka.KafkaConsumer .assign`.
756
767
757
768
Arguments:
758
769
topics (list): List of topics for subscription.
@@ -781,7 +792,8 @@ def subscribe(self, topics=(), pattern=None, listener=None):
781
792
through this interface are from topics subscribed in this call.
782
793
783
794
Raises:
784
- IllegalStateError: If called after previously calling :meth:`.assign`.
795
+ IllegalStateError: If called after previously calling
796
+ :meth:`~kafka.KafkaConsumer.assign`.
785
797
AssertionError: If neither topics or pattern is provided.
786
798
TypeError: If listener is not a ConsumerRebalanceListener.
787
799
"""
0 commit comments