DataScience_Examples

All about DataSince, DataEngineering and ComputerScience

View the Project on GitHub datainsightat/DataScience_Examples

General

Architecture

Kafka Brokers

Kafka Concepts

Acks

Safe Producer Settings

Compression

Kafka Connect

Connect Kafka to other applications.

Kafka Connect

Commands

Topic

$ kafka-topics.sh --zookeeper 0.0.0.0:2181 --topic first_topic --create --partitions 3 --replication-factor 1
$ kafka-topics.sh --zookeeper 0.0.0.0:2181 --list
$ kafka-topics.sh --zookeeper 0.0.0.0:2181 --topic first_topic --describe

Producer

$ kafka-console-producer.sh --broker-list 0.0.0.0:9092 --topic first_topic
> first
> second
> ...
$ kafka-console-producer.sh --broker-list 0.0.0.0:9092 --topic first_topic --producer-property acks=all
> third
> fourth
> ...

Consumer

Only messages that are currently streamed by the producer are displayed by the consumer

$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic

Sho historic messages

$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic --from-beginning

Consumer Group

Messages are split between consumers within the same consumer group by the topic partitions

$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic --group my-first-application
$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic --group my-first-application
$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic --group my-first-application

Get status consumer group

$ kafka-consumer-groups.sh --bootstrap-server 0.0.0.0:9092 --describe --group my-first-application

GROUP                TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG
my-first-application first_topic     0          0               1               1
my-first-application first_topic     1          1               2               1
my-first-application first_topic     2          1               2               1

Catch up Messages

$ kafka-console-consumer.sh --bootstrap-server 0.0.0.0:9092 --topic first_topic --group my-first-application
$ kafka-consumer-groups.sh --bootstrap-server 0.0.0.0:9092 --describe --group my-first-application

GROUP                TOPIC           PARTITION  CURRENT-OFFSET  LOG-END-OFFSET  LAG
my-first-application first_topic     0          1               1               0
my-first-application first_topic     1          2               2               0
my-first-application first_topic     2          2               2               0

Reset Offsets

$ kafka-consumer-groups.sh --bootstrap-server 0.0.0.0:9092 --group my-first-application --reset-offsets --to-earliest --execute --topic first_topic