您的位置:首页 > 其它

windows环境下用命令行操作kafka

2018-02-28 09:46 746 查看
转载自https://www.cnblogs.com/mignet/p/window_kafka.html

1.通过cmd进入kafka_2.11-0.9.0.1\bin\windows目录

2.启动zk

zookeeper-server-start ..\..\config\zookeeper.properties

测试连接一下

zookeeper-shell.bat 0.0.0.0:2181

3.启动Kafka

kafka-server-start.bat ..\..\config\server.properties

4.创建topic

kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic mytopic
参数的含义可以自查,当前无视
Created topic "mytopic".
 
5.查看topic
kafka-topics.bat --describe --zookeeper localhost:2181 --topic mytopic
----------------------------------------------------------
Topic:mytopic PartitionCount:3 ReplicationFactor:1 Configs:
Topic: mytopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: mytopic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
6.发布/生产消息窗口
kafka-console-producer.bat --broker-list localhost:9092 --topic mytopic
 
7.消费消息窗口
kafka-console-consumer.bat --zookeeper localhost:2181 --from-beginning --topic mytopic
 
8.在生产者producer窗口输入,可以在consumer窗口看到输出
bin\windows>kafka-console-producer.bat --broker-list localhost:9092 --topic mytopic
--------------------------------------------------------------------
你真坚决
niaho
heelo
我是中文啊

bin\windows>kafka-console-consumer.bat --zookeeper localhost:2181 --from-beginning --topic mytopic
--------------------------------------------------------------------

你真坚决
niaho
heelo
我是中文啊

--------------------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  kafka