Kafka producers

Apache Kafka เบื้องต้น

Mike Metzger

Data Engineering Consultant

Producer คืออะไร?

  • เขียนข้อความไปยัง Kafka topics
    • บางครั้งเรียกว่า publisher
  • ข้อความที่ส่งผ่าน producer จะถูกเก็บไว้ใน Kafka เพื่อใช้ในภายหลัง
  • มี producer ได้หลายตัวพร้อมกัน
  • Producer สามารถเขียนไปยัง topic เดียวหรือหลาย topic ได้
Apache Kafka เบื้องต้น

ประเภทของ producer

  • Producer มีหลายประเภท
    • Command-line
      • kafka-console-producer.sh
    • Python
    • Java
    • ภาษาอื่นๆ อีกมาก
    • Kafka Connect
Apache Kafka เบื้องต้น

kafka-console-producer.sh

  • อยู่ในโฟลเดอร์ bin/ พร้อมกับเครื่องมือ Kafka อื่นๆ
    • bin/kafka-console-producer.sh
  • มี option ใน command-line หลายตัว บางตัวบังคับใช้ บางตัวไม่บังคับ
  • Option ที่บังคับใช้:
    • --bootstrap-server - ระบุเซิร์ฟเวอร์ที่ต้องการใช้
      • --bootstrap-server localhost:9092
    • --topic
      • --topic phishing-sites
  • โดยค่าเริ่มต้น จะเปิดการเชื่อมต่อเพื่อพิมพ์ข้อความ
    • ใช้ Ctrl-C เพื่อออก
  • สามารถใช้สัญลักษณ์ | เพื่อส่งข้อความได้เช่นกัน
Apache Kafka เบื้องต้น

ตัวอย่าง

  • ตัวอย่างแบบ interactive
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>
  • แบบ non-interactive
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...