本文整理汇总了Python中kafka.coordinator.consumer.ConsumerCoordinator.commit_offsets_sync方法的典型用法代码示例。如果您正苦于以下问题:Python ConsumerCoordinator.commit_offsets_sync方法的具体用法?Python ConsumerCoordinator.commit_offsets_sync怎么用?Python ConsumerCoordinator.commit_offsets_sync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.coordinator.consumer.ConsumerCoordinator
的用法示例。
在下文中一共展示了ConsumerCoordinator.commit_offsets_sync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KafkaConsumer
# 需要导入模块: from kafka.coordinator.consumer import ConsumerCoordinator [as 别名]
# 或者: from kafka.coordinator.consumer.ConsumerCoordinator import commit_offsets_sync [as 别名]
#.........这里部分代码省略.........
a commit request completes.
Returns:
kafka.future.Future
"""
assert self.config["api_version"] >= (0, 8, 1)
if offsets is None:
offsets = self._subscription.all_consumed_offsets()
log.debug("Committing offsets: %s", offsets)
future = self._coordinator.commit_offsets_async(offsets, callback=callback)
return future
def commit(self, offsets=None):
"""Commit offsets to kafka, blocking until success or error
This commits offsets only to Kafka. The offsets committed using this API
will be used on the first fetch after every rebalance and also on
startup. As such, if you need to store offsets in anything other than
Kafka, this API should not be used.
Blocks until either the commit succeeds or an unrecoverable error is
encountered (in which case it is thrown to the caller).
Currently only supports kafka-topic offset storage (not zookeeper)
Arguments:
offsets (dict, optional): {TopicPartition: OffsetAndMetadata} dict
to commit with the configured group_id. Defaults to current
consumed offsets for all subscribed partitions.
"""
assert self.config["api_version"] >= (0, 8, 1)
if offsets is None:
offsets = self._subscription.all_consumed_offsets()
self._coordinator.commit_offsets_sync(offsets)
def committed(self, partition):
"""Get the last committed offset for the given partition
This offset will be used as the position for the consumer
in the event of a failure.
This call may block to do a remote call if the partition in question
isn't assigned to this consumer or if the consumer hasn't yet
initialized its cache of committed offsets.
Arguments:
partition (TopicPartition): the partition to check
Returns:
The last committed offset, or None if there was no prior commit.
"""
assert self.config["api_version"] >= (0, 8, 1)
if self._subscription.is_assigned(partition):
committed = self._subscription.assignment[partition].committed
if committed is None:
self._coordinator.refresh_committed_offsets_if_needed()
committed = self._subscription.assignment[partition].committed
else:
commit_map = self._coordinator.fetch_committed_offsets([partition])
if partition in commit_map:
committed = commit_map[partition].offset
else:
committed = None
return committed
def topics(self):