本文整理汇总了Python中kafka.coordinator.consumer.ConsumerCoordinator.ensure_active_group方法的典型用法代码示例。如果您正苦于以下问题:Python ConsumerCoordinator.ensure_active_group方法的具体用法?Python ConsumerCoordinator.ensure_active_group怎么用?Python ConsumerCoordinator.ensure_active_group使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.coordinator.consumer.ConsumerCoordinator
的用法示例。
在下文中一共展示了ConsumerCoordinator.ensure_active_group方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KafkaConsumer
# 需要导入模块: from kafka.coordinator.consumer import ConsumerCoordinator [as 别名]
# 或者: from kafka.coordinator.consumer.ConsumerCoordinator import ensure_active_group [as 别名]
#.........这里部分代码省略.........
records = self._poll_once(remaining)
if records:
# before returning the fetched records, we can send off the
# next round of fetches and avoid block waiting for their
# responses to enable pipelining while the user is handling the
# fetched records.
self._fetcher.init_fetches()
return records
elapsed_ms = (time.time() - start) * 1000
remaining = timeout_ms - elapsed_ms
if remaining <= 0:
return {}
def _poll_once(self, timeout_ms):
"""
Do one round of polling. In addition to checking for new data, this does
any needed heart-beating, auto-commits, and offset updates.
Arguments:
timeout_ms (int): The maximum time in milliseconds to block
Returns:
dict: map of topic to list of records (may be empty)
"""
if self.config["api_version"] >= (0, 8, 2):
# TODO: Sub-requests should take into account the poll timeout (KAFKA-1894)
self._coordinator.ensure_coordinator_known()
if self.config["api_version"] >= (0, 9):
# ensure we have partitions assigned if we expect to
if self._subscription.partitions_auto_assigned():
self._coordinator.ensure_active_group()
# fetch positions if we have partitions we're subscribed to that we
# don't know the offset for
if not self._subscription.has_all_fetch_positions():
self._update_fetch_positions(self._subscription.missing_fetch_positions())
# init any new fetches (won't resend pending fetches)
records = self._fetcher.fetched_records()
# if data is available already, e.g. from a previous network client
# poll() call to commit, then just return it immediately
if records:
return records
self._fetcher.init_fetches()
self._client.poll(timeout_ms)
return self._fetcher.fetched_records()
def position(self, partition):
"""Get the offset of the next record that will be fetched
Arguments:
partition (TopicPartition): partition to check
"""
assert self._subscription.is_assigned(partition)
offset = self._subscription.assignment[partition].position
if offset is None:
self._update_fetch_positions(partition)
offset = self._subscription.assignment[partition].position
return offset