public class CooperativeStickyAssignor
extends org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
AbstractStickyAssignor
. This follows the same (sticky)
assignment logic as StickyAssignor
but allows for cooperative rebalancing while the
StickyAssignor
follows the eager rebalancing protocol. See
ConsumerPartitionAssignor.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 returns RebalanceProtocol.COOPERATIVE
in
supportedProtocols()
.
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.
org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData
org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo
ConsumerPartitionAssignor.Assignment, ConsumerPartitionAssignor.GroupAssignment, ConsumerPartitionAssignor.GroupSubscription, ConsumerPartitionAssignor.RebalanceProtocol, ConsumerPartitionAssignor.Subscription
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
COOPERATIVE_STICKY_ASSIGNOR_NAME |
Constructor and Description |
---|
CooperativeStickyAssignor() |
Modifier and Type | Method and 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.
|
void |
onAssignment(ConsumerPartitionAssignor.Assignment assignment,
ConsumerGroupMetadata metadata)
Callback which is invoked when a group member receives its assignment from the leader.
|
java.nio.ByteBuffer |
subscriptionUserData(java.util.Set<java.lang.String> topics)
Return serialized data that will be included in the
ConsumerPartitionAssignor.Subscription sent to the leader
and can be leveraged in ConsumerPartitionAssignor.assign(Cluster, GroupSubscription) ((e.g. |
java.util.List<ConsumerPartitionAssignor.RebalanceProtocol> |
supportedProtocols()
Indicate which rebalance protocol this assignor works with;
By default it should always work with
ConsumerPartitionAssignor.RebalanceProtocol.EAGER . |
isSticky
assign, partitions, put
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
version
public static final java.lang.String COOPERATIVE_STICKY_ASSIGNOR_NAME
public java.lang.String name()
ConsumerPartitionAssignor
ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG
public java.util.List<ConsumerPartitionAssignor.RebalanceProtocol> supportedProtocols()
ConsumerPartitionAssignor
ConsumerPartitionAssignor.RebalanceProtocol.EAGER
.public void onAssignment(ConsumerPartitionAssignor.Assignment assignment, ConsumerGroupMetadata metadata)
ConsumerPartitionAssignor
assignment
- The local member's assignment as provided by the leader in ConsumerPartitionAssignor.assign(Cluster, GroupSubscription)
metadata
- Additional metadata on the consumer (optional)public java.nio.ByteBuffer subscriptionUserData(java.util.Set<java.lang.String> topics)
ConsumerPartitionAssignor
ConsumerPartitionAssignor.Subscription
sent to the leader
and can be leveraged in ConsumerPartitionAssignor.assign(Cluster, GroupSubscription)
((e.g. local host/rack information)topics
- Topics subscribed to through KafkaConsumer.subscribe(java.util.Collection)
and variantsprotected org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData memberData(ConsumerPartitionAssignor.Subscription subscription)
memberData
in class org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor
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)
assign
in class org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor