Interface TaskAssignor
- All Superinterfaces:
Configurable
- All Known Implementing Classes:
StickyTaskAssignor
A TaskAssignor is responsible for creating a TaskAssignment from a given
ApplicationState
.
The implementation may also override the onAssignmentComputed
callback for insight into
the result of the assignment result.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
NONE: no error detected ACTIVE_TASK_ASSIGNED_MULTIPLE_TIMES: multiple KafkaStreams clients assigned with the same active task INVALID_STANDBY_TASK: stateless task assigned as a standby task MISSING_PROCESS_ID: ProcessId present in the input ApplicationState was not present in the output TaskAssignment UNKNOWN_PROCESS_ID: unrecognized ProcessId not matching any of the participating consumers UNKNOWN_TASK_ID: unrecognized TaskId not matching any of the tasks to be assignedstatic class
Wrapper class for the final assignment of active and standbys tasks to individual KafkaStreams clients. -
Method Summary
Modifier and TypeMethodDescriptionassign
(ApplicationState applicationState) default void
Configure this class with the given key-value pairsdefault void
onAssignmentComputed
(ConsumerPartitionAssignor.GroupAssignment assignment, ConsumerPartitionAssignor.GroupSubscription subscription, TaskAssignor.AssignmentError error) This callback can be used to observe the final assignment returned to the brokers and check for any errors that were detected while processing the returned assignment.
-
Method Details
-
assign
- Parameters:
applicationState
- the metadata for this Kafka Streams application- Returns:
- the assignment of active and standby tasks to KafkaStreams clients
- Throws:
TaskAssignmentException
- If an error occurs during assignment, and you wish for the rebalance to be retried, you can throw this exception to keep the assignment unchanged and automatically schedule an immediate followup rebalance.
-
onAssignmentComputed
default void onAssignmentComputed(ConsumerPartitionAssignor.GroupAssignment assignment, ConsumerPartitionAssignor.GroupSubscription subscription, TaskAssignor.AssignmentError error) This callback can be used to observe the final assignment returned to the brokers and check for any errors that were detected while processing the returned assignment. If any errors were found, the corresponding will be returned and a StreamsException will be thrown after this callback returns. The StreamsException will be thrown up to kill the StreamThread and can be handled as any other uncaught exception would if the application has registered aStreamsUncaughtExceptionHandler
.Note: some kinds of errors will make it impossible for the StreamsPartitionAssignor to parse the TaskAssignment that was returned from the TaskAssignor's
assign(org.apache.kafka.streams.processor.assignment.ApplicationState)
. If this occurs, theConsumerPartitionAssignor.GroupAssignment
passed in to this callback will contain an empty map instead of the consumer assignments.- Parameters:
assignment
- : the final consumer assignments returned to the kafka broker, or an empty assignment map if an error prevented the assignor from converting the TaskAssignment into a GroupAssignmentsubscription
- : the original consumer subscriptions passed into the assignorerror
- : the corresponding error type if one was detected while processing the returned assignment, or AssignmentError.NONE if the returned assignment was valid
-
configure
Description copied from interface:Configurable
Configure this class with the given key-value pairs- Specified by:
configure
in interfaceConfigurable
-