Consommateurs Kafka

Introduction à Apache Kafka

Mike Metzger

Data Engineering Consultant

Qu'est-ce qu'un consommateur ?

  • Lit des messages depuis des topics Kafka
    • Parfois appelés abonnés
  • Kafka fournit aux consommateurs les messages stockés dans les topics
  • Peut y avoir de nombreux consommateurs
  • Les consommateurs peuvent lire un ou plusieurs topics
Introduction à Apache Kafka

Types de consommateurs

  • De nombreux types de consommateurs
    • Ligne de commande
      • kafka-console-consumer.sh
    • Python
    • Java
    • Beaucoup d'autres langages
    • Kafka Connect
Introduction à Apache Kafka

kafka-console-consumer.sh

  • Se trouve dans le dossier bin/, avec les autres outils Kafka
    • bin/kafka-console-consumer.sh
  • Plusieurs options, certaines obligatoires
  • Options obligatoires, comme pour kafka-console-producer :
    • --topic
    • --bootstrap-server
  • Par défaut, ouvre une connexion où les messages arrivent en temps réel et conserve la position.
  • Utilisez Ctrl-C pour quitter
Introduction à 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
Introduction à 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>
Introduction à 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>
Introduction à Apache Kafka

Let's practice!

Introduction à Apache Kafka

Preparing Video For Download...