Class RoundRobinAssignor
- java.lang.Object
-
- org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
-
- org.apache.kafka.clients.consumer.RoundRobinAssignor
-
- All Implemented Interfaces:
ConsumerPartitionAssignor
public class RoundRobinAssignor extends org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
The round robin assignor lays out all the available partitions and all the available consumers. It then proceeds to do a round robin assignment from partition to consumer. If the subscriptions of all consumer instances are identical, then the partitions will be uniformly distributed. (i.e., the partition ownership counts will be within a delta of exactly one across all consumers.)
For example, suppose there are two consumers
C0
andC1
, two topicst0
andt1
, and each topic has 3 partitions, resulting in partitionst0p0
,t0p1
,t0p2
,t1p0
,t1p1
, andt1p2
.The assignment will be:
C0: [t0p0, t0p2, t1p1]
C1: [t0p1, t1p0, t1p2]
When subscriptions differ across consumer instances, the assignment process still considers each consumer instance in round robin fashion but skips over an instance if it is not subscribed to the topic. Unlike the case when subscriptions are identical, this can result in imbalanced assignments. For example, we have three consumers
C0
,C1
,C2
, and three topicst0
,t1
,t2
, with 1, 2, and 3 partitions, respectively. Therefore, the partitions aret0p0
,t1p0
,t1p1
,t2p0
,t2p1
,t2p2
.C0
is subscribed tot0
;C1
is subscribed tot0
,t1
; andC2
is subscribed tot0
,t1
,t2
.That assignment will be:
C0: [t0p0]
C1: [t1p0]
C2: [t1p1, t2p0, t2p1, t2p2]
group.instance.id
to make the assignment behavior more sticky. For example, we have three consumers with assignedmember.id
C0
,C1
,C2
, two topicst0
andt1
, and each topic has 3 partitions, resulting in partitionst0p0
,t0p1
,t0p2
,t1p0
,t1p1
, andt1p2
. We choose to honor the sorted order based on ephemeralmember.id
.The assignment will be:
C0: [t0p0, t1p0]
C1: [t0p1, t1p1]
C2: [t0p2, t1p2]
member.id
towards consumers, for exampleC0
->C5
C1
->C3
,C2
->C4
.The assignment could be completely shuffled to:
C3 (was C1): [t0p0, t1p0] (before was [t0p1, t1p1])
C4 (was C2): [t0p1, t1p1] (before was [t0p2, t1p2])
C5 (was C0): [t0p2, t1p2] (before was [t0p0, t1p0])
I1
,I2
,I3
. As long as 1. Number of members remain the same across generation 2. Static members' identities persist across generation 3. Subscription pattern doesn't change for any memberThe assignment will always be:
I0: [t0p0, t1p0]
I1: [t0p1, t1p1]
I2: [t0p2, t1p2]
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo
-
Nested classes/interfaces inherited from interface org.apache.kafka.clients.consumer.ConsumerPartitionAssignor
ConsumerPartitionAssignor.Assignment, ConsumerPartitionAssignor.GroupAssignment, ConsumerPartitionAssignor.GroupSubscription, ConsumerPartitionAssignor.RebalanceProtocol, ConsumerPartitionAssignor.Subscription
-
-
Constructor Summary
Constructors Constructor Description RoundRobinAssignor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,List<TopicPartition>>
assign(Map<String,Integer> partitionsPerTopic, Map<String,ConsumerPartitionAssignor.Subscription> subscriptions)
String
name()
Unique name for this assignor (e.g.-
Methods inherited from class org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
assign, partitions, put
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.kafka.clients.consumer.ConsumerPartitionAssignor
onAssignment, subscriptionUserData, supportedProtocols, version
-
-
-
-
Method Detail
-
assign
public Map<String,List<TopicPartition>> assign(Map<String,Integer> partitionsPerTopic, Map<String,ConsumerPartitionAssignor.Subscription> subscriptions)
- Specified by:
assign
in classorg.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
-
name
public String name()
Description copied from interface:ConsumerPartitionAssignor
Unique name for this assignor (e.g. "range" or "roundrobin" or "sticky"). Note, this is not required to be the same as the class name specified inConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG
- Returns:
- non-null unique name
-
-