Kafka partitions, producers and consumers by example
I will show 3 cases for running Kafka topic, first case is the topic has 2 partitions and 1 consumer group that has 2 consumers.
In the second case, the topic has 2 partitions, and we have 2 consumer groups each with 1 consumer.
In the third case, the topic has 2 partitions, and we have 2 consumer groups each with 1 consumer. moreover, we producer produce the message using keys (which control the target partition for the message).
The following are 3 diagrams illustrate the 3 cases, and it following by 2 screenshots of terminal windows illustrating the cases as well.
Case 1:
Case 2:
Case 3:
Here are the terminal windows that illustrate the above 3 cases:
This terminal window for case 1 and 2, sending messages with no key, and receive it with 2 consumer group, one of them has 2 consumers:
This terminal window for case 3:(sending messages with a key):
That’s all! Thanks.