Kafka 生產者

Apache Kafka 入門

Mike Metzger

Data Engineering Consultant

什麼是生產者?

  • 將訊息寫入 Kafka 主題
    • 有時稱為發佈者
  • 透過生產者送出的訊息會儲存在 Kafka,供日後使用
  • 可有多個生產者
  • 生產者可寫入一個或多個主題
Apache Kafka 入門

生產者類型

  • 生產者型態很多
    • 命令列
      • kafka-console-producer.sh
    • Python
    • Java
    • 其他多種語言
    • Kafka Connect
Apache Kafka 入門

kafka-console-producer.sh

  • 與其他 Kafka 工具一起位於 bin/ 資料夾
    • bin/kafka-console-producer.sh
  • 有多個命令列選項,部分必填,部分選填
  • 必填選項:
    • --bootstrap-server-指定要使用的伺服器
      • --bootstrap-server localhost:9092
    • --topic
      • --topic phishing-sites
  • 預設會開啟可輸入訊息的連線
    • 使用 Ctrl-C 離開
  • 也可用 | 將訊息導入
Apache Kafka 入門

範例

  • 互動式範例
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic testing
>This is the first message
>This is the second message
>This is the third message
<ctrl+c to exit>
  • 非互動式
echo "This is the first message" |
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic testing
Apache Kafka 入門

一起來練習吧!

Apache Kafka 入門

Preparing Video For Download...