kafka学习笔记--常用指令

常用指令:

//新建虚拟窗口 kafka,在每台上执行

$ screen -S kafka

// 退出虚拟窗口 kafka,在每台上执行 $ Ctrl+A+D

1.// 创建 topic

$ kafka-topics.sh --create --zookeeper cluster1:2181,cluster2:2181,cluster3:2181 --replication-factor 3 --partitions 1 --topic mykafka

2.// 查看 Topic:

$ kafka-topics.sh --list --zookeeper cluster1:2181,cluster2:2181,cluster3:2181(此时会显示 Topic:mykafka)

3.// 查看详细信息

$ kafka-topics.sh --describe --zookeeper cluster1:2181,cluster2:2181,cluster3:2181

4.// 发送消息(cluster1 上执行)

$ kafka-console-producer.sh --broker-list localhost:9092 --topic mykafka

5.// 接收消息(cluster2 上执行)

$ kafka-console-consumer.sh -zookeeper cluster1:2181,cluster2:2181,cluster3:2181 --topic mykafka --from-beginning

// 在 cluster1 输入以下内容

test

mycluster test

可以在 cluster2 上看到相应的信息。

按 Ctrl+C 退出。

6.删除话题mykafka

$ kafka-topics.sh --delete --zookeeper cluster1:2181,cluster2:2181,cluster3:2181 --topic mykafka

原文地址:https://www.cnblogs.com/bao-ZhangJiao/p/14268768.html