kafka的基本使用
kafka基本使用
安装kafka
-
启动kafka
./kafka-server-start.sh -daemon ../config/server.properties
常用命令
note: 所用命令默认在kafka安装目录中的bin目录
-
创建topic主题
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
-
查看主题
./kafka-topics.sh --list --zookeeper localhost:2181
-
测试发送消息
./kafka-console-producer.sh --broker-list localhost:9000 --topic test1
-
新开终端,接收消息
./kafka-console-consumer.sh --bootstrap-server localhost:9000 --topic test1 --from-beginning
-
是否真正删除topic
vim ../config/server.properties delete.topic.enable=true # 如果不配置,删除动作仅仅是标记删除,并未真正彻底删除
-
删除topic
./kafka-topics.sh --delete --zookeeper localhost:2181 --topic test1