①創(chuàng)建一個測試用的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 生產(chǎn)消息
/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內(nèi)容:
/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的 詳細(xì)信息
/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的內(nèi)部生產(chǎn)消息
/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的內(nèi)部消費消息
/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
文章來源地址http://www.zghlxwxcb.cn/news/detail-506377.html
文章來源:http://www.zghlxwxcb.cn/news/detail-506377.html
到了這里,關(guān)于kafka查看topic和消息內(nèi)容命令的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!