PacktPublishing / Apache-Kafka-Series---Learn-Apache-Kafka-for-Beginners-v3

Code Repository for Apache Kafka Series - Learn Apache Kafka for Beginners, Published by Packt
MIT License
37 stars 30 forks source link

Exercise "Kafka Consumers in a Group" not working: all the messages end up read from the same consumer #1

Closed witlingw closed 1 year ago

witlingw commented 1 year ago

Hello,

I don't know if there has been some changes in the newer versions of Kafka but the exercise to demonstrate the messages being read from a random consumer in a consumer group in case of multiple partitions doesn't work for me.

Reproducer I have launched kafka with KRaft as explained in the video. I created 1 topic with 3 partitions and opened 3 consumers in the same group: kafka-topics.sh --bootstrap-server localhost:9092 --create --topic my_topic --partitions 3

lgattoni:~$ kafka-topics.sh --bootstrap-server localhost:9092 --describe
Topic: my_topic TopicId: CCw5AV7RSaOwlqFL19oXEQ PartitionCount: 3       ReplicationFactor: 1    Configs: segment.bytes=1073741824
        Topic: my_topic Partition: 0    Leader: 1       Replicas: 1     Isr: 1
        Topic: my_topic Partition: 1    Leader: 1       Replicas: 1     Isr: 1
        Topic: my_topic Partition: 2    Leader: 1       Replicas: 1     Isr: 1

Then opened 1 producer and 3 consumers like this: kafka-console-producer.sh --bootstrap-server localhost:9092 --topic my_topic kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic my_topic --group uat * 3 times

only 1 of the consumers receive the messages.

System Specifications WSL2 Ubuntu kafka_2.13-3.4.0 openjdk 17.0.6 2023-01-17 OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10) OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)

UPDATE: I have tried to launch kafka with zookeeper and the very first message ended up in one consumer while all the other ones in another.

Maybe the default method to split the messages in the partitions have changed?

Sonakshis commented 1 year ago

Hi @witlingw, We are currently in the process of updating the course. Thank you for your patience!

Sonakshis commented 1 year ago

Hi @witlingw We have updated the course. Thank you so much for your patience!