--- title: Apache Kafka command 紀錄 tags: Apache, Kafka description: Apache Kafka command 紀錄 --- # Apache Kafka Command 紀錄 需要安裝好 kafka 環境,詳細安裝內容請參考[**上一篇**](https://hackmd.io/exY8zB_YSXSzj88jBx5JWQ),本篇以上一篇多機器多broker環境進行示範,首先進入 kafka 目錄下 ``` $ cd kafka_2.13-3.0.0 ``` ## 創建 Topic ``` $ bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 5 --partitions 1 --topic test3 ```  ## 查看 Topic 信息 ``` $ bin/kafka-topics.sh --describe --bootstrap-server localhost:9092 --topic test3 ```  * Topic: Topic key 名稱 * Partition: 文件有多少內容 * Leader: Topic 的 leader在哪一個節點上 * replicas:列出了所有的節點,不管節點是否在服務中 * isr:正在服務中的節點 ## 向 Topic 寫入訊息 ``` $ bin/kafka-console-producer.sh --topic test3 --bootstrap-server localhost:9092 > This is first test3 event > This is second test3 event ```  ## 讀取 Topic 訊息 ``` $ bin/kafka-console-consumer.sh --topic test3 --from-beginning --bootstrap-server localhost:9092 This is my first test3 event This is my second test3 event ``` ## 刪除 Topic ``` $ bin/kafka-topics.sh --delete --topic test3 --bootstrap-server localhost:9092 ``` --- ## 參考 * https://kknews.cc/zh-tw/code/rbppbov.html ## Thank you! :dash: You can find me on - GitHub: https://github.com/shaung08 - Email: a2369875@gmail.com
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up