本文整理匯總了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)