本文整理匯總了Python中aiokafka.client.AIOKafkaClient.send_produce_request方法的典型用法代碼示例。如果您正苦於以下問題:Python AIOKafkaClient.send_produce_request方法的具體用法?Python AIOKafkaClient.send_produce_request怎麽用?Python AIOKafkaClient.send_produce_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aiokafka.client.AIOKafkaClient
的用法示例。
在下文中一共展示了AIOKafkaClient.send_produce_request方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_send_produce_request_raises_when_noleader
# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import send_produce_request [as 別名]
def test_send_produce_request_raises_when_noleader(self, protocol):
"""Send producer request raises LeaderNotAvailableError
if leader is not available"""
@asyncio.coroutine
def recv(request_id):
return b"response"
mocked_conns = {("broker_1", 4567): mock.MagicMock()}
mocked_conns[("broker_1", 4567)].recv.side_effect = recv
client = AIOKafkaClient(["broker_1:4567"], loop=self.loop)
client._conns = mocked_conns
brokers = [BrokerMetadata(0, "broker_1", 4567), BrokerMetadata(1, "broker_2", 5678)]
topics = [
TopicMetadata(
"topic_noleader",
NO_ERROR,
[
PartitionMetadata("topic_noleader", 0, -1, [], [], NO_LEADER),
PartitionMetadata("topic_noleader", 1, -1, [], [], NO_LEADER),
],
)
]
protocol.decode_metadata_response.return_value = MetadataResponse(brokers, topics)
self.loop.run_until_complete(client.load_metadata_for_topics())
requests = [ProduceRequest("topic_noleader", 0, [create_message("a"), create_message("b")])]
with self.assertRaises(LeaderNotAvailableError):
self.loop.run_until_complete(client.send_produce_request(requests))
示例2: test_send_produce_request_raises_when_topic_unknown
# 需要導入模塊: from aiokafka.client import AIOKafkaClient [as 別名]
# 或者: from aiokafka.client.AIOKafkaClient import send_produce_request [as 別名]
def test_send_produce_request_raises_when_topic_unknown(self, protocol):
@asyncio.coroutine
def recv(request_id):
return b"response"
mocked_conns = {("broker_1", 4567): mock.MagicMock()}
mocked_conns[("broker_1", 4567)].recv.side_effect = recv
client = AIOKafkaClient(["broker_1:4567"], loop=self.loop)
client._conns = mocked_conns
brokers = [BrokerMetadata(0, "broker_1", 4567), BrokerMetadata(1, "broker_2", 5678)]
topics = [TopicMetadata("topic_doesnt_exist", UNKNOWN_TOPIC_OR_PARTITION, [])]
protocol.decode_metadata_response.return_value = MetadataResponse(brokers, topics)
self.loop.run_until_complete(client.load_metadata_for_topics())
requests = [ProduceRequest("topic_doesnt_exist", 0, [create_message("a"), create_message("b")])]
with self.assertRaises(UnknownTopicOrPartitionError):
self.loop.run_until_complete(client.send_produce_request(requests))