Consumidores do Kafka

Introdução ao Apache Kafka

Mike Metzger

Data Engineering Consultant

O que é um consumidor?

  • Lê mensagens de tópicos do Kafka
    • Também chamados de assinantes
  • O Kafka entrega mensagens armazenadas nos tópicos aos consumidores
  • Pode haver muitos consumidores
  • Consumidores podem ler de um ou vários tópicos
Introdução ao Apache Kafka

Types of consumers

  • Muitos tipos de consumidores
    • Linha de comando
      • kafka-console-consumer.sh
    • Python
    • Java
    • Muitas outras linguagens
    • Kafka Connect
Introdução ao 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
Introdução ao 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
Introdução ao 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>
Introdução ao 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>
Introdução ao Apache Kafka

Let's practice!

Introdução ao Apache Kafka

Preparing Video For Download...