當前位置: 首頁>>代碼示例>>Python>>正文


Python AIOKafkaProducer.flush方法代碼示例

本文整理匯總了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())
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:16,代碼來源:test_producer.py

示例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)
開發者ID:aio-libs,項目名稱:aiokafka,代碼行數:20,代碼來源:test_producer.py


注:本文中的aiokafka.producer.AIOKafkaProducer.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。