一、生产与消费
#消费
./bin/kafka-console-consumer.sh --bootstrap-server master:9092,slave1:9092,slave2:9092 --topic topic2
#生产
./bin/kafka-console-producer.sh --broker-list master:9092,slave1:9092,slave2:9092 --topic topic2
二、创建、删除、查看topic信息
#删除
./bin/kafka-topics.sh --zookeeper master:2181,slave1:2181,slave2:2181 --delete --topic topic2
#列出所有topic
./bin/kafka-topics.sh --zookeeper master:2181,slave1:2181,slave2:2181 --list
#创建
./bin/kafka-topics.sh --zookeeper master:2181,slave1:2181,slave2:2181 --create --replication-factor 3 --partitions 3 --topic topic2
./bin/kafka-list-topic.sh --zookeeper master:2181,slave1:2181,slave2:2181 --topic topic2
查看group情况
查看consumer group列表,使用–list参数 查看consumer group列表有新、旧两种命令,分别查看新版(信息保存在broker中)consumer列表和老版(信息保存在zookeeper中)consumer列表,因而需要区分指定bootstrap–server和zookeeper参数:
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9292 --list
bin/kafka-consumer-groups.sh --zookeeper localhost:2181 --list
查看特定consumer group 详情,使用–group与–describe参数 同样根据新/旧版本的consumer,分别指定bootstrap-server与zookeeper参数
//新版本
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9292 --list //展示所有group
bin/kafka-consumer-groups.sh --new-consumer --bootstrap-server localhost:9292 --group group1 --describe
//旧版本
bin/kafka-consumer-groups.sh --zookeeper 127.0.0.1:2181 --group console-consumer-11967 --describe
其中依次展示group名称、消费的topic名称、partition id、consumer group最后一次提交的offset、最后提交的生产消息offset、消费offset与生产offset之间的差值、当前消费topic-partition的group成员id(不一定包含hostname) 上面示例中console-consumer是为了测试临时起的一个console consumer,缺少在zookeeper中保存的current_offset信息。
查询kafka消费情况, offset ./kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper dn1:2181 --group test-general-1