Interface ConsumerPartitionAssignor
- All Known Implementing Classes:
- org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor,- org.apache.kafka.clients.consumer.internals.AbstractStickyAssignor,- CooperativeStickyAssignor,- RangeAssignor,- RoundRobinAssignor,- StickyAssignor
public interface ConsumerPartitionAssignor
This interface is used to define custom partition assignment for use in
 
KafkaConsumer. Members of the consumer group subscribe
 to the topics they are interested in and forward their subscriptions to a Kafka broker serving
 as the group coordinator. The coordinator selects one member to perform the group assignment and
 propagates the subscriptions of all members to it. Then assign(Cluster, GroupSubscription) is called
 to perform the assignment and the results are forwarded back to each respective members
 In some cases, it is useful to forward additional metadata to the assignor in order to make
 assignment decisions. For this, you can override subscriptionUserData(Set) and provide custom
 userData in the returned Subscription. For example, to have a rack-aware assignor, an implementation
 can use this user data to forward the rackId belonging to each member.- 
Nested Class SummaryNested ClassesModifier and TypeInterfaceDescriptionstatic final classstatic final classstatic final classstatic enumThe rebalance protocol defines partition assignment and revocation semantics.static final class
- 
Method SummaryModifier and TypeMethodDescriptionassign(Cluster metadata, ConsumerPartitionAssignor.GroupSubscription groupSubscription) Perform the group assignment given the member subscriptions and current cluster metadata.static List<ConsumerPartitionAssignor>Get a list of configured instances ofConsumerPartitionAssignorbased on the class names/types specified byConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIGname()Unique name for this assignor (e.g.default voidonAssignment(ConsumerPartitionAssignor.Assignment assignment, ConsumerGroupMetadata metadata) Callback which is invoked when a group member receives its assignment from the leader.default ByteBuffersubscriptionUserData(Set<String> topics) Return serialized data that will be included in theConsumerPartitionAssignor.Subscriptionsent to the leader and can be leveraged inassign(Cluster, GroupSubscription)((e.g. local host/rack information)Indicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER.default shortversion()Return the version of the assignor which indicates how the user metadata encodings and the assignment algorithm gets evolved.
- 
Method Details- 
subscriptionUserDataReturn serialized data that will be included in theConsumerPartitionAssignor.Subscriptionsent to the leader and can be leveraged inassign(Cluster, GroupSubscription)((e.g. local host/rack information)- Parameters:
- topics- Topics subscribed to through- KafkaConsumer.subscribe(java.util.Collection)and variants
- Returns:
- nullable subscription user data
 
- 
assignConsumerPartitionAssignor.GroupAssignment assign(Cluster metadata, ConsumerPartitionAssignor.GroupSubscription groupSubscription) Perform the group assignment given the member subscriptions and current cluster metadata.- Parameters:
- metadata- Current topic/broker metadata known by consumer
- groupSubscription- Subscriptions from all members including metadata provided through- subscriptionUserData(Set)
- Returns:
- A map from the members to their respective assignments. This should have one entry for each member in the input subscription map.
 
- 
onAssignmentdefault void onAssignment(ConsumerPartitionAssignor.Assignment assignment, ConsumerGroupMetadata metadata) Callback which is invoked when a group member receives its assignment from the leader.- Parameters:
- assignment- The local member's assignment as provided by the leader in- assign(Cluster, GroupSubscription)
- metadata- Additional metadata on the consumer (optional)
 
- 
supportedProtocolsIndicate which rebalance protocol this assignor works with; By default it should always work withConsumerPartitionAssignor.RebalanceProtocol.EAGER.
- 
versiondefault short version()Return the version of the assignor which indicates how the user metadata encodings and the assignment algorithm gets evolved.
- 
nameString name()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
 
- 
getAssignorInstancesstatic List<ConsumerPartitionAssignor> getAssignorInstances(List<String> assignorClasses, Map<String, Object> configs) Get a list of configured instances ofConsumerPartitionAssignorbased on the class names/types specified byConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG
 
-