Споживачі Kafka

Вступ до Apache Kafka

Mike Metzger

Data Engineering Consultant

Що таке споживач?

  • Читають повідомлення з топіків Kafka
    • Іноді їх називають підписниками
  • Kafka надає повідомлення з топіків споживачам
  • Може бути багато споживачів
  • Споживачі можуть читати з одного або кількох топіків
Вступ до Apache Kafka

Типи споживачів

  • Є багато типів споживачів
    • Командний рядок
      • kafka-console-consumer.sh
    • Python
    • Java
    • Багато інших мов
    • Kafka Connect
Вступ до Apache Kafka

kafka-console-consumer.sh

  • Found in bin/ folder, with other Kafka tools
    • bin/kafka-console-consumer.sh
  • Several options, some required
  • Required options same as kafka-console-producer:
    • --topic
    • --bootstrap-server
  • By default, opens a connection where messages appear (real-time) and maintain position.
  • Use Ctrl-C to exit
Вступ до Apache Kafka

Optional arguments

  • --from-beginning
    • Tells the Kafka system to send all messages in topic, even ones that may have been already read.
  • --max-messages <number>
    • Used to read up to a maximum number of messages before exiting
Вступ до Apache Kafka

Interactive example

  • Interactive example
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 \
    --topic testing --from-beginning
This is the first message
This is the second message
This is the third message
<ctrl+c to exit>
Вступ до Apache Kafka

Non-interactive example

  • Non-interactive
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 /
  --topic testing --from-beginning --max-messages 2
This is the first message
This is the second message
<automatically exits>
Вступ до Apache Kafka

Let's practice!

Вступ до Apache Kafka

Preparing Video For Download...