本文整理汇总了Python中aiokafka.client.AIOKafkaClient.fetch_all_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaClient.fetch_all_metadata方法的具体用法?Python AIOKafkaClient.fetch_all_metadata怎么用?Python AIOKafkaClient.fetch_all_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient.fetch_all_metadata方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_metadata_update_fail
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import fetch_all_metadata [as 别名]
def test_metadata_update_fail(self):
client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
yield from client.bootstrap()
with mock.patch.object(
AIOKafkaConnection, 'send') as mocked:
mocked.side_effect = KafkaError('mocked exception')
updated = yield from client.force_metadata_update()
self.assertEqual(updated, False)
with self.assertRaises(KafkaError):
yield from client.fetch_all_metadata()
示例2: test_metadata_update_fail
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import fetch_all_metadata [as 别名]
def test_metadata_update_fail(self):
client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
yield from client.bootstrap()
# Make sure the connection is initialize before mock to avoid crashing
# api_version routine
yield from client.force_metadata_update()
with mock.patch.object(
AIOKafkaConnection, 'send') as mocked:
mocked.side_effect = KafkaError('mocked exception')
updated = yield from client.force_metadata_update()
self.assertEqual(updated, False)
with self.assertRaises(KafkaError):
yield from client.fetch_all_metadata()
yield from client.close()
示例3: test_bootstrap
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import fetch_all_metadata [as 别名]
def test_bootstrap(self):
client = AIOKafkaClient(loop=self.loop,
bootstrap_servers='0.42.42.42:444')
with self.assertRaises(ConnectionError):
yield from client.bootstrap()
client = AIOKafkaClient(loop=self.loop, bootstrap_servers=self.hosts)
yield from client.bootstrap()
yield from self.wait_topic(client, 'test_topic')
metadata = yield from client.fetch_all_metadata()
self.assertTrue('test_topic' in metadata.topics())
client.set_topics(['t2', 't3'])
client.set_topics(['t2', 't3']) # should be ignored
client.add_topic('t2') # shold be ignored
# bootstrap again -- no error expected
yield from client.bootstrap()
yield from client.close()
示例4: AIOKafkaConsumer
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import fetch_all_metadata [as 别名]
#.........这里部分代码省略.........
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._group_id is not None, 'Requires group_id'
if self._subscription.is_assigned(partition):
committed = self._subscription.assignment[partition].committed
if committed is None:
yield from self._coordinator.refresh_committed_offsets()
committed = self._subscription.assignment[partition].committed
else:
commit_map = yield from self._coordinator.fetch_committed_offsets(
[partition])
if partition in commit_map:
committed = commit_map[partition].offset
else:
committed = None
return committed
@asyncio.coroutine
def topics(self):
"""Get all topics the user is authorized to view.
Returns:
set: topics
"""
cluster = yield from self._client.fetch_all_metadata()
return cluster.topics()
def partitions_for_topic(self, topic):
"""Get metadata about the partitions for a given topic.
Arguments:
topic (str): topic to check
Returns:
set: partition ids
"""
return self._client.cluster.partitions_for_topic(topic)
@asyncio.coroutine
def position(self, partition):
"""Get the offset of the next record that will be fetched
Arguments:
partition (TopicPartition): partition to check
Returns:
int: offset
"""
assert self._subscription.is_assigned(partition), \
'Partition is not assigned'
offset = self._subscription.assignment[partition].position
if offset is None:
yield from self._update_fetch_positions(partition)
offset = self._subscription.assignment[partition].position
return offset
def highwater(self, partition):