Class CooperativeStickyAssignor
- java.lang.Object
-
- org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor
-
- org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
-
- org.apache.kafka.clients.consumer.CooperativeStickyAssignor
-
- All Implemented Interfaces:
ConsumerPartitionAssignor
public class CooperativeStickyAssignor extends org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
A cooperative version of theAbstractStickyAssignor
. This follows the same (sticky) assignment logic asStickyAssignor
but allows for cooperative rebalancing while theStickyAssignor
follows the eager rebalancing protocol. SeeConsumerPartitionAssignor.RebalanceProtocol
for an explanation of the rebalancing protocols.Users should prefer this assignor for newer clusters.
To turn on cooperative rebalancing you must set all your consumers to use this
PartitionAssignor
, or implement a custom one that returnsRebalanceProtocol.COOPERATIVE
insupportedProtocols()
.IMPORTANT: if upgrading from 2.3 or earlier, you must follow a specific upgrade path in order to safely turn on cooperative rebalancing. See the upgrade guide for details.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData
-
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 CooperativeStickyAssignor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.util.List<TopicPartition>>
assign(java.util.Map<java.lang.String,java.lang.Integer> partitionsPerTopic, java.util.Map<java.lang.String,ConsumerPartitionAssignor.Subscription> subscriptions)
protected org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData
memberData(ConsumerPartitionAssignor.Subscription subscription)
java.lang.String
name()
Unique name for this assignor (e.g.java.util.List<ConsumerPartitionAssignor.RebalanceProtocol>
supportedProtocols()
Indicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER
.-
Methods inherited from class org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
isSticky
-
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, version
-
-
-
-
Method Detail
-
name
public java.lang.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
-
supportedProtocols
public java.util.List<ConsumerPartitionAssignor.RebalanceProtocol> supportedProtocols()
Description copied from interface:ConsumerPartitionAssignor
Indicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER
.
-
memberData
protected org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData memberData(ConsumerPartitionAssignor.Subscription subscription)
- Specified by:
memberData
in classorg.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
-
assign
public java.util.Map<java.lang.String,java.util.List<TopicPartition>> assign(java.util.Map<java.lang.String,java.lang.Integer> partitionsPerTopic, java.util.Map<java.lang.String,ConsumerPartitionAssignor.Subscription> subscriptions)
- Overrides:
assign
in classorg.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
-
-