Python測試Kafka集群(pykafka)實例
更新時間:2019年12月23日 09:10:37 作者:右介
今天小編就為大家分享一篇Python測試Kafka集群(pykafka)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
生產(chǎn)者代碼:
# -* coding:utf8 *- from pykafka import KafkaClient host = 'IP:9092, IP:9092, IP:9092' client = KafkaClient(hosts = host) print client.topics # 生產(chǎn)者 topicdocu = client.topics['my-topic'] producer = topicdocu.get_producer() for i in range(100): print i producer.produce('test message ' + str(i ** 2)) producer.stop()
消費者代碼:
# -* coding:utf8 *- from pykafka import KafkaClient host = 'IP:9092, IP:9092, IP:9092' client = KafkaClient(hosts = host) print client.topics # 消費者 topic = client.topics['my-topic'] consumer = topic.get_simple_consumer(consumer_group='test', auto_commit_enable=True, auto_commit_interval_ms=1, consumer_id='test') for message in consumer: if message is not None: print message.offset, message.value
以上這篇Python測試Kafka集群(pykafka)實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
pandas將多個dataframe以多個sheet的形式保存到一個excel文件中
這篇文章主要介紹了pandas將多個dataframe以多個sheet的形式保存到一個excel文件中,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-10-10Keras 數(shù)據(jù)增強ImageDataGenerator多輸入多輸出實例
這篇文章主要介紹了Keras 數(shù)據(jù)增強ImageDataGenerator多輸入多輸出實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07