Python測(cè)試Kafka集群(pykafka)實(shí)例
更新時(shí)間:2019年12月23日 09:10:37 作者:右介
今天小編就為大家分享一篇Python測(cè)試Kafka集群(pykafka)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
生產(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()
消費(fèi)者代碼:
# -* coding:utf8 *-
from pykafka import KafkaClient
host = 'IP:9092, IP:9092, IP:9092'
client = KafkaClient(hosts = host)
print client.topics
# 消費(fèi)者
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測(cè)試Kafka集群(pykafka)實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
pandas將多個(gè)dataframe以多個(gè)sheet的形式保存到一個(gè)excel文件中
這篇文章主要介紹了pandas將多個(gè)dataframe以多個(gè)sheet的形式保存到一個(gè)excel文件中,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
如何用Pytorch搭建一個(gè)房?jī)r(jià)預(yù)測(cè)模型
這篇文章主要介紹了用Pytorch搭建一個(gè)房?jī)r(jià)預(yù)測(cè)模型,在這里我將主要討論P(yáng)yTorch建模的相關(guān)方面,作為一點(diǎn)額外的內(nèi)容,我還將演示PyTorch中開發(fā)的模型的神經(jīng)元重要性,需要的朋友可以參考下2023-03-03
python 使用正則表達(dá)式按照多個(gè)空格分割字符的實(shí)例
今天小編就為大家分享一篇python 使用正則表達(dá)式按照多個(gè)空格分割字符的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12
Python+Tkinter繪制一個(gè)數(shù)字時(shí)鐘
這篇文章主要為大家詳細(xì)介紹了Python使用Tkinter繪制一個(gè)數(shù)字時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
Keras 數(shù)據(jù)增強(qiáng)ImageDataGenerator多輸入多輸出實(shí)例
這篇文章主要介紹了Keras 數(shù)據(jù)增強(qiáng)ImageDataGenerator多輸入多輸出實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07

