天天看点

kafka 常用命令

一、创建topic:

kafka-topics.sh --create --replication-factor 1 --partitions 3 --zookeeper localhost:2181 --topic wklc-nginx-weixin

二、查看topic list:

kafka-topics.sh --zookeeper 127.0.0.1 --list

三、查看单个topic:

kafka-topics.sh --zookeeper 127.0.0.1 --topic api3-nginx --describe

四、从console消费:

kafka-console-consumer.sh --topic wklc-nginx --zookeeper 127.0.0.1:2181 --from-beginning

五、修改topic partitions:

kafka-topics.sh --zookeeper 127.0.0.1 --topic api3-nginx --alter --partitions 3

六、删除topic:

kafka-topics.sh --delete --zookeeper 127.0.0.1 --topic wklc-nginx

七、修改topic config:

kafka-topics.sh --zookeeper localhost:2181 --create --topic my-topic --partitions 1 --replication-factor 1 --config max.message.bytes=64000 --config flush.messages=1

八、修改topic数据存储时间

./kafka-topics.sh --zookeeper 127.0.0.1:2181 -topic coreservice-tomcat --alter --config retention.ms=21600000