Produser Kafka

Pengantar Apache Kafka

Mike Metzger

Data Engineering Consultant

Apa itu produser?

  • Menulis pesan ke topik Kafka
    • Kadang disebut publisher
  • Pesan dari produser disimpan di Kafka untuk dipakai nanti
  • Bisa ada banyak produser
  • Produser bisa menulis ke satu atau beberapa topik
Pengantar Apache Kafka

Jenis produser

  • Banyak jenis produser
    • Command line
      • kafka-console-producer.sh
    • Python
    • Java
    • Banyak bahasa lain
    • Kafka Connect
Pengantar Apache Kafka

kafka-console-producer.sh

  • Ada di folder bin/, bersama alat Kafka lain
    • bin/kafka-console-producer.sh
  • Beberapa opsi command line, ada yang wajib, ada yang opsional
  • Opsi wajib:
    • --bootstrap-server - Menentukan server yang dipakai
      • --bootstrap-server localhost:9092
    • --topic
      • --topic phishing-sites
  • Default: membuka koneksi untuk mengetik pesan
    • Gunakan Ctrl-C untuk keluar
  • Juga bisa pakai simbol | untuk meneruskan pesan
Pengantar Apache Kafka

Contoh

  • Contoh interaktif
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-interaktif
echo "This is the first message" |
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic testing
Pengantar Apache Kafka

Ayo berlatih!

Pengantar Apache Kafka

Preparing Video For Download...