kafka在windows环境下用命令行操作

首先需要下载安装kafka,jdk为1.8

1.首先通过cmd进入kafka_2.12-1.0.1\bin\windows目录

2.启动zookeeper

 

 

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

 

 

该命令需要指定zookeeper的配置文件位置才能正确启动,启动失败可能出现端口占用,修改配置文件端口号或者kill进程

端口号默认2181


测试连接一下
zookeeper-shell.bat 0.0.0.0:2181

3.启动Kafka

 

 

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

 

 

该命令需要指定kafka的配置文件位置


4.创建一个名为mytest的topic
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic mytest

 

参数的含义可以自查,当前无视

 

查看当前的Kafka中的所有Topic

kafka-topics.bat --list--zookeeper localhost:2181


5.查看topic
kafka-topics.bat --describe --zookeeper localhost:2181 --topic mytest
----------------------------------------------------------
Topic:mytest PartitionCount:3 ReplicationFactor:1 Configs:
Topic: mytest Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: mytest Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: mytest Partition: 2 Leader: 0 Replicas: 0 Isr: 0
6.发布/生产消息窗口,端口号默认为9092 
kafka-console-producer.bat --broker-list localhost:9092 --topic mytest
 
7.消费消息窗口
kafka-console-consumer.bat --zookeeper localhost:2181 --from-beginning --topic mytest
 
8.在生产者producer窗口输入,可以在consumer窗口看到输出
bin\windows>kafka-console-producer.bat --broker-list localhost:9092 --topic mytest
--------------------------------------------------------------------

 

test

hello

 

nice to meet you



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

 

test

hello

 

nice to meet you


中文的话会出现乱码,这个可能与你编译器的环境有关
--------------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值