Kafka-consumers

Introductie tot Apache Kafka

Mike Metzger

Data Engineering Consultant

Wat is een consumer?

  • Leest berichten van Kafka-topics
    • Worden ook wel subscribers genoemd
  • Kafka levert berichten in topics aan consumers
  • Je kunt veel consumers hebben
  • Consumers kunnen uit één of meerdere topics lezen
Introductie tot Apache Kafka

Types consumers

  • Veel soorten consumers
    • Command line
      • kafka-console-consumer.sh
    • Python
    • Java
    • Veel andere talen
    • Kafka Connect
Introductie tot Apache Kafka

kafka-console-consumer.sh

  • Staat in de map bin/, met andere Kafka-tools
    • bin/kafka-console-consumer.sh
  • Meerdere opties, sommige verplicht
  • Verplichte opties, net als bij kafka-console-producer:
    • --topic
    • --bootstrap-server
  • Opent standaard een verbinding waar berichten realtime verschijnen en positie wordt onthouden.
  • Gebruik Ctrl-C om te stoppen
Introductie tot Apache Kafka

Optionele argumenten

  • --from-beginning
    • Vraagt Kafka alle berichten in het topic te sturen, ook al gelezen berichten.
  • --max-messages <number>
    • Leest tot maximaal dit aantal berichten en stopt dan
Introductie tot Apache Kafka

Interactief voorbeeld

  • Interactief voorbeeld
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>
Introductie tot Apache Kafka

Niet-interactief voorbeeld

  • Niet-interactief
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>
Introductie tot Apache Kafka

Laten we oefenen!

Introductie tot Apache Kafka

Preparing Video For Download...