本文整理汇总了Python中aiokafka.producer.AIOKafkaProducer.flush方法的典型用法代码示例。如果您正苦于以下问题:Python AIOKafkaProducer.flush方法的具体用法?Python AIOKafkaProducer.flush怎么用?Python AIOKafkaProducer.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiokafka.producer.AIOKafkaProducer
的用法示例。
在下文中一共展示了AIOKafkaProducer.flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_producer_flush_test
# 需要导入模块: from aiokafka.producer import AIOKafkaProducer [as 别名]
# 或者: from aiokafka.producer.AIOKafkaProducer import flush [as 别名]
def test_producer_flush_test(self):
producer = AIOKafkaProducer(
loop=self.loop, bootstrap_servers=self.hosts)
yield from producer.start()
self.add_cleanup(producer.stop)
fut1 = yield from producer.send("producer_flush_test", b'text1')
fut2 = yield from producer.send("producer_flush_test", b'text2')
self.assertFalse(fut1.done())
self.assertFalse(fut2.done())
yield from producer.flush()
self.assertTrue(fut1.done())
self.assertTrue(fut2.done())
示例2: test_producer_send_empty_batch
# 需要导入模块: from aiokafka.producer import AIOKafkaProducer [as 别名]
# 或者: from aiokafka.producer.AIOKafkaProducer import flush [as 别名]
def test_producer_send_empty_batch(self):
# We trigger a unique case here, we don't send any messages, but the
# ProduceBatch will be created. It should be discarded as it contains
# 0 messages by sender routine.
producer = AIOKafkaProducer(
loop=self.loop, bootstrap_servers=self.hosts)
yield from producer.start()
self.add_cleanup(producer.stop)
with self.assertRaises(TypeError):
yield from producer.send(self.topic, 'text1')
send_mock = mock.Mock()
send_mock.side_effect = producer._sender._send_produce_req
producer._sender._send_produce_req = send_mock
yield from producer.flush()
self.assertEqual(send_mock.call_count, 0)