KafKa常用命令总结

Kafka常用操作命令

查看当前服务器中所有topic

[root]# ./bin/kafka-topics.sh --list --zookeeper 10.240.185.37:2181
__consumer_offsets
advancedtopic
basictopic

查看某个Topic的详情

[root]# bin/kafka-topics.sh --topic advancedtopic --describe --zookeeper 10.240.185.37:2181
Topic:advancedtopic	PartitionCount:1	ReplicationFactor:1	Configs:
	Topic: advancedtopic	Partition: 0	Leader: 0	Replicas: 0	Isr: 0

创建Topic

[root]# bin/kafka-topics.sh --create --zookeeper 10.240.185.37:2181 --replication-factor 1 --partitions 1 --topic test 
Created topic "test".

删除Topic

[root]# bin/kafka-topics.sh --zookeeper 10.240.185.37:2181 --list
__consumer_offsets
advancedtopic
basictopic
streams-wordcount-output
test - marked for deletion

向Topic发送消息

[root]#bin/kafka-console-producer.sh --broker-list 10.240.185.37:9092 --topic advancedtopic
>whdwiedhweidhqwe89dfy8wefywe8f
>adfwefhweuifhewufhcweufhweu
>ecwecwecwecccccccccccccccccwcwe

从Topic中接收数据

[root]# bin/kafka-console-consumer.sh --bootstrap-server 10.240.185.37:9092 --topic advancedtopic
whdwiedhweidhqwe89dfy8wefywe8f
adfwefhweuifhewufhcweufhweu
ewefwefwecfwecewcccccccccccwcwe

如果再加上 --from-beginning,会接收所有历史的消息

你可能感兴趣的:(Java后端知识)