Does this mean if I want to have more than 1 consumer (from the same group) reading from one topic I need to have more than 1 section?
Let's look at the following properties of kafka:
- each section is consumed by exactly one consumer in the group
- one consumer in a group can use more than one section
- the number of consumer processes in the group should be & lt; = number of partitions
Thanks to these properties, kafka can provide both ordering guarantees and load balancing through a pool of user processes.
To answer your question, yes, in the context of the same group, if you want to have N consumers , you must have at least N partitions .
Does this mean that I need the same number of sections as the number of consumers? for the same group?
I think this was explained in the first answer.
How many consumers can read from one section?
number of consumers , which can read from one section, is always equal to the number of consumer groups subscribing to this topic.
The relationship between keys and sections in relation to the API
First, we must understand that producer is responsible for choosing the record that should be assigned to a particular section in the topic.
Now let's see how the producer does this. First, let's look at the definition of the ProducerRecord.java class:
public class ProducerRecord<K, V> { private final String topic; private final Integer partition; private final Headers headers; private final K key; private final V value; private final Long timestamp; }
Here the field we need to understand from the class is partition .
From the documents
- If a valid
partition number is specified, this partition will be used when sending the record. - If a section is not specified but
key present, the section will be selected using hash of the key . - If neither
key nor partition present, the partition will be assigned in round-robin fashion .
oblivion
source share