本文整理汇总了Python中aiokafka.client.AIOKafkaClient._wait_on_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaClient._wait_on_metadata方法的具体用法?Python AIOKafkaClient._wait_on_metadata怎么用?Python AIOKafkaClient._wait_on_metadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient._wait_on_metadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AIOKafkaProducer
# 需要导入模块: from aiokafka.client import AIOKafkaClient [as 别名]
# 或者: from aiokafka.client.AIOKafkaClient import _wait_on_metadata [as 别名]
#.........这里部分代码省略.........
yield from self._sender.start()
self._message_accumulator.set_api_version(self.client.api_version)
self._producer_magic = 0 if self.client.api_version < (0, 10) else 1
log.debug("Kafka producer started")
@asyncio.coroutine
def flush(self):
"""Wait untill all batches are Delivered and futures resolved"""
yield from self._message_accumulator.flush()
@asyncio.coroutine
def stop(self):
"""Flush all pending data and close all connections to kafka cluster"""
if self._closed:
return
self._closed = True
# If the sender task is down there is no way for accumulator to flush
if self._sender is not None and self._sender.sender_task is not None:
yield from asyncio.wait([
self._message_accumulator.close(),
self._sender.sender_task],
return_when=asyncio.FIRST_COMPLETED,
loop=self._loop)
yield from self._sender.close()
yield from self.client.close()
log.debug("The Kafka producer has closed.")
@asyncio.coroutine
def partitions_for(self, topic):
"""Returns set of all known partitions for the topic."""
return (yield from self.client._wait_on_metadata(topic))
def _serialize(self, topic, key, value):
if self._key_serializer:
serialized_key = self._key_serializer(key)
else:
serialized_key = key
if self._value_serializer:
serialized_value = self._value_serializer(value)
else:
serialized_value = value
message_size = LegacyRecordBatchBuilder.record_overhead(
self._producer_magic)
if serialized_key is not None:
message_size += len(serialized_key)
if serialized_value is not None:
message_size += len(serialized_value)
if message_size > self._max_request_size:
raise MessageSizeTooLargeError(
"The message is %d bytes when serialized which is larger than"
" the maximum request size you have configured with the"
" max_request_size configuration" % message_size)
return serialized_key, serialized_value
def _partition(self, topic, partition, key, value,
serialized_key, serialized_value):
if partition is not None:
assert partition >= 0
assert partition in self._metadata.partitions_for_topic(topic), \
'Unrecognized partition'
return partition