Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Kafka broadcast to many Consumer Groups

Tags:

apache-kafka

I am new to Kafka and I will appreciate very much clarification on the next case.

Kafka documentation says in the paragraph "Consumer Position":

"Our topic is divided into a set of totally ordered partitions, each of which is consumed by one consumer at any given time."

Based on statement above if few Consumer Groups subscribed to a topic and Producer will publish message to particular partition within this topic then only one Consumer can pull the message.

The question is how broadcast to many Consumer Groups could happen if only one Consumer can pull particular message?

like image 241
ivan_d Avatar asked Apr 17 '14 14:04

ivan_d


People also ask

How does Kafka deal with multiple consumers?

You can't have multiple consumers that belong to the same group in one thread and you can't have multiple threads safely use the same consumer. One consumer per thread is the rule. To run multiple consumers in the same group in one application, you will need to run each in its own thread.

How many consumer groups can Kafka handle?

While Kafka allows only one consumer per topic partition, there may be multiple consumer groups reading from the same partition.

Can multiple consumers consume the same message Kafka?

The same message can be consumed several times, either by different consumers, or indeed by the same consumer multiple times. Kafka uses the concepts of topics and partitions, where partitions are the main mechanism used to achieve its impressive scalability characteristics.

How does Kafka consumer read from multiple partitions?

The consumers in a group divide the topic partitions as fairly amongst themselves as possible by establishing that each partition is only consumed by a single consumer from the group. When the number of consumers is lower than partitions, same consumers are going to read messages from more than one partition.


1 Answers

Only one consumer in a consumer group can pull the message. But all consumer groups get the messages.

So if you want all your consumers to get the messages, assign them different consumer groups. Each message goes to every consumer group, but within a group, it goes to only one consumer.

Read the Consumer section here.

like image 98
gaganbm Avatar answered Sep 23 '22 11:09

gaganbm