①创建一个测试用的topic
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
② 用Kafka的console-producer在topic test 生产消息
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-console-producer.sh --broker-list admin01:9092,admin02:9092,admin03:9092 --topic test
③ 用Kafka的console-consumer 消费topic test的消息
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-console-consumer.sh --bootstrap-server admin01:9092,admin02:9092,admin03:9092 --topic test --from-beginning
④查询topic,进入kafka目录:
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-topics.sh --list --zookeeper localhost:2181
⑤查询topic内容:
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-console-consumer.sh --bootstrap-server admin01:9092,admin02:9092,admin03:9092 --topic logstash-kafka-devops-log-topic --from-beginning
⑥查看topic 为 test的 详细信息
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-topics.sh --bootstrap-server admin01:9092,admin02:9092,admin03:9092 --describe --topic test
⑦往topic 为 test的内部生产消息
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-console-producer.sh --broker-list admin01:9092,admin02:9092,admin03:9092 --topic test
⑧从topic 为test的内部消费消息
/data/usr/local/kafka_2.12-1.0.0/bin/kafka-console-consumer.sh --bootstrap-server admin01:9092,admin02:9092,admin03:9092 --topic test
⑨删除kafka的测试topic test
/data/kafka_2.11-1.1.0/bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test
文章来源地址https://www.toymoban.com/news/detail-506377.html
文章来源:https://www.toymoban.com/news/detail-506377.html
到了这里,关于kafka查看topic和消息内容命令的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!