Fork me on GitHub

Kafka简单使用

启动zookeeper

> bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

启动Kafka Server

> bin/kafka-server-start.sh config/server.properties

Topic相关

创建Topic

新版命令:
> bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic [topic-name]

查看所有topic列表

> bin/kafka-topics.sh --list --bootstrap-server localhost:9092

查看某个topic的信息

> bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic [topic-name]

修改某个topic的partition个数(分区数只能增不能减)

> bin/kafka-topics.sh --bootstrap-server localhost:2181 --alter --topic [topic-name] --partitions [new-partitions-count]
eg: > bin/kafka-topics.sh --bootstrap-server localhost:2181 --alter --topic topic-test --partitions 10

Producer相关

Producer生产消息

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic [topic-name]

Consumer相关

查看所有消费者组

> bin/kafka-consumer-groups --bootstrap-server localhost:9092 --list

查看指定group(group01)的消费情况

> bin/kafka-consumer-groups --describe --group group01 --bootstrap-server localhost:9092

Consumer消费消息

> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic [topic-name]

posted @ 2023-05-20 10:42  Hui_Li  阅读(7)  评论(0编辑  收藏  举报