_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › KafkaQuickStart

Contents

1 れ 覦 ろ
2
3 谿瑚


Windows 10 ろ

1 れ 覦 ろ #

[https]襯 谿瑚.
JRE螳 れ 伎 .
蟆暑 JAVA_HOME 誤伎 . JAVA_HOME C:\Program Files\Java\jdk-13.0.2.

1. れ企 覦 豢 伎( D:\kafka_2.12-2.5.0)
2. 覈轟綾 れ螻 螳 譯狩ろ ろ
d:
cd D:\kafka_2.12-2.5.0\bin\windows
zookeeper-server-start.bat D:\kafka_2.12-2.5.0\config\zookeeper.properties

3. 覈轟綾 襯 郁, れ螻 螳 豺危豺 ろ
d:
cd D:\kafka_2.12-2.5.0\bin\windows
kafka-server-start.bat D:\kafka_2.12-2.5.0\config/server.properties

4. 覈轟綾 襯 郁, 曙 襷.
d:
cd D:\kafka_2.12-2.5.0\bin\windows
kafka-topics.bat --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
kafka-topics.bat --list --bootstrap-server localhost:9092

5. 覈轟綾 襯 郁, れ ろ
producer
d:
cd D:\kafka_2.12-2.5.0\bin\windows
kafka-console-producer.bat --bootstrap-server localhost:9092 --topic test
ctrl+c襯 襯企 螳, 蠏碁 .

6. 覈轟綾 襯 郁, れ ろ
consumer
d:
cd D:\kafka_2.12-2.5.0\bin\windows
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning

蠏碁
  • 覈轟綾 producer
  • 覈轟綾 consumer

覈轟綾 覃讌襯 企ロ覃 覈轟綾 襴壱 蟆 覲 .

kafka_test.png

2 #

pip install kafka-python

from kafka import KafkaConsumer
import sys

bootstrap_servers = ["localhost:9092"]
topicName = 'test'
consumer = KafkaConsumer(topicName, group_id='group1', bootstrap_servers=bootstrap_servers, auto_offset_reset='earliest')

for message in consumer:
    print(message.value)


'''
try:
    for message in consumer:
        #print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,message.offset, message.key,message.value))
        print(message.value)
except KeyboardInterrupt:
    sys.exit()
'''   

るゼ ろ覃 producer螳 覃讌襯 讌 襷 豢ル 蟆 覲 .

蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2021-04-23 10:18:44

覓企Μ 覯企 覈 蟆 る 語蟆 覯碁 企.