linux下
1:启动Kafka
./bin/kafka-server-start.sh -daemon config/server.properties
#或者
./kafka-server-start.sh ../config/server.properties
1.1:查看状态
jps
2:停止Kafka
./bin/kafka-server-stop.sh
3:创建Topic
./bin/kafka-topics.sh --create --zookeeper 172.16.0.11:2181 --replication-factor 1 --partitions 1 --topic demo-topic
4:查看已经创建的Topic信息
./bin/kafka-topics.sh --list --zookeeper 172.16.0.11:2181
5:发送消息
./bin/kafka-console-producer.sh --broker-list 172.16.0.11:9092 --topic demo-topic
#./bin/kafka-console-producer.sh --broker-list 172.16.0.11:9092 --topic 名称
6:接收消息
./bin/kafka-console-consumer.sh --bootstrap-server 172.16.0.11:9092 --topic demo-topic --from-beginning
#./bin/kafka-console-consumer.sh --bootstrap-server 172.16.0.11:9092 --topic 名称 --from-beginning
7:给指定的topic创建 partition
#./bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic 主题名称 --partitions 分区数量
#将demo-topic的partitions从1增加到9;
./bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic demo-topic --partitions 9
8:查看topci下partition的数量
./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic 主题名称
windows的docker下
1:创建一个topic 名为demo1
bin/kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic demo1
2:查看我们的topic列表
bin/kafka-topics.sh --list --zookeeper zookeeper:2181
3:产生一个生产者,发送消息
#bin/kafka-console-producer.sh --broker-list localhost:9092 --topic topic名
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic demo1
4:创建一个消息接收者
#bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic名 --from-beginning
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test01 --from-beginning
windows的docker和linux的命令对比
bin/kafka-topics.sh --alter --zookeeper zookeeper:2181 --topic demo1 --partitions 9
./bin/kafka-topics.sh --alter --zookeeper localhost:2181 --topic demo-topic --partitions 9
发现一个特点。docker在linux1的基础上,不需要bin前面按的./ 以及将localhost(端口)改为zookeeper就行