##################################################
常用的差不多就这些,我是现记录
##################################################
1、topic列表
[root@t1-25-19 bin]# ./kafka-topics.sh --list --zookeeper localhost:2181/kfk_mq
__consumer_offsets
bd_frs
crs_events
2、创建topic
[root@t1-25-19 bin]# ./kafka-topics.sh --create --zookeeper localhost:2181/kfk_mq --replication-factor 3 --partitions 3 --topic demo
Created topic "demo".
3、修改topic
[root@t1-25-19 bin]# ./kafka-topics.sh --alter --topic demo --zookeeper localhost:2181/kfk_mq --partitions 4
WARNING: If partitions are increased for a topic that has a key, the partition logic or ordering of the messages will be affected
Adding partitions succeeded!
4、删除topic
[root@t1-25-19 bin]# ./kafka-topics.sh --delete --zookeeper localhost:2181/kfk_mq --topic demo
Topic demo is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
5、查看topic信息
[root@t1-25-19 bin]# ./kafka-topics.sh --zookeeper localhost:2181/kfk_mq --describe --topic demo
Topic:demo PartitionCount:3 ReplicationFactor:3 Configs:
Topic: demo Partition: 0 Leader: 1002 Replicas: 1002,1001,1003 Isr: 1002,1001,1003
Topic: demo Partition: 1 Leader: 1003 Replicas: 1003,1002,1001 Isr: 1003,1002,1001
Topic: demo Partition: 2 Leader: 1001 Replicas: 1001,1003,1002 Isr: 1001,1003,1002
5、消费topic
[root@t1-25-19 bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181/kfk_mq --topic demo --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
{metadata.broker.list=t1-25-19.bigdata:6667,t1-25-21.bigdata:6667,t1-25-20.bigdata:6667, request.timeout.ms=30000, client.id=console-consumer-25274, security.protocol=PLAINTEXT}
6、生产消息
123是输入内容,此时打开消费就能收到消息了
[root@t1-25-19 bin]# ./kafka-console-producer.sh --broker-list t1-25-19.bigdata:6667 --topic demo
123
7、消费指定偏移量消息
./kafka-console-consumer.sh --bootstrap-server 172.16.2.63:6667 --topic test --partition 0 --offset 2654 --max-messages 1 --property print.timestamp=true
- offset偏移量
- max-message展示的最大数据
8、查询当前topic某分区中数据的偏移量信息
./kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 172.16.2.63:6667 --topic crs_events --time -1 --partitions 0
注: time为-1时表示最大值,time为-2时表示最小值