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 String |
COOPERATIVE_STICKY_ASSIGNOR_NAME |
Constructor and Description |
---|
CooperativeStickyAssignor() |
Modifier and Type | Method and Description |
---|---|
Map<String,List<TopicPartition>> |
assignPartitions(Map<String,List<PartitionInfo>> partitionsPerTopic,
Map<String,ConsumerPartitionAssignor.Subscription> subscriptions) |
protected org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor.MemberData |
memberData(ConsumerPartitionAssignor.Subscription subscription) |
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.
|
ByteBuffer |
subscriptionUserData(Set<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. |
List<ConsumerPartitionAssignor.RebalanceProtocol> |
supportedProtocols()
Indicate which rebalance protocol this assignor works with;
By default it should always work with
ConsumerPartitionAssignor.RebalanceProtocol.EAGER . |
assign, isSticky, maxGeneration, partitionsTransferringOwnership
assign, partitionInfosWithoutRacks, partitions, put, useRackAwareAssignment
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAssignorInstances, version
public static final String COOPERATIVE_STICKY_ASSIGNOR_NAME
public String name()
ConsumerPartitionAssignor
ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG
public 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 ByteBuffer subscriptionUserData(Set<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 Map<String,List<TopicPartition>> assignPartitions(Map<String,List<PartitionInfo>> partitionsPerTopic, Map<String,ConsumerPartitionAssignor.Subscription> subscriptions)
assignPartitions
in class org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor