Interface MembershipManager
- All Known Implementing Classes:
MembershipManagerImpl
public interface MembershipManager
A stateful object tracking the state of a single member in relationship to a consumer group:
Responsible for:
Keeping member state
Keeping assignment for the member
Computing assignment for the group if the member is required to do so
-
Method Summary
Modifier and TypeMethodDescriptionvoidSignals that aConsumerRebalanceListenercallback has completed.groupId()booleanisStaled()Release assignment and transition toMemberState.PREPARE_LEAVINGso that a heartbeat request is sent indicating the broker that the member wants to leave the group.intmemberId()voidUpdate state when a heartbeat is sent out.voidTransition out of theMemberState.LEAVINGstate even if the heartbeat was not sent .voidonHeartbeatResponseReceived(org.apache.kafka.common.message.ConsumerGroupHeartbeatResponseData response) Update member info and transition member state based on a successful heartbeat response.voidJoin the group with the updated subscription, if the member is not part of it yet.voidregisterStateListener(MemberStateListener listener) Register a listener that will be called whenever the member state changes due to transitions of new data received from the server, as defined inMemberStateListener.booleanbooleanstate()voidTransition the member to the FAILED state and update the member info as required.voidTransition the member to the FENCED state, where the member will release the assignment by calling the onPartitionsLost callback, and when the callback completes, it will transition toMemberState.JOININGto rejoin the group.voidTransition to theMemberState.JOININGstate to attempt joining a group.voidWhen the user stops polling the consumer and themax.poll.interval.mstimer expires, we transition the member to STALE.
-
Method Details
-
groupId
String groupId()- Returns:
- Group ID of the consumer group the member is part of (or wants to be part of).
-
groupInstanceId
- Returns:
- Instance ID used by the member when joining the group. If non-empty, it will indicate that this is a static member.
-
memberId
String memberId()- Returns:
- Member ID assigned by the server to this member when it joins the consumer group.
-
memberEpoch
int memberEpoch()- Returns:
- Current epoch of the member, maintained by the server.
-
state
MemberState state()- Returns:
- Current state of this member in relationship to a consumer group, as defined in
MemberState.
-
isStaled
boolean isStaled()- Returns:
- True if the member is staled due to expired poll timer.
-
onHeartbeatResponseReceived
void onHeartbeatResponseReceived(org.apache.kafka.common.message.ConsumerGroupHeartbeatResponseData response) Update member info and transition member state based on a successful heartbeat response.- Parameters:
response- Heartbeat response to extract member info and errors from.
-
onHeartbeatRequestSent
void onHeartbeatRequestSent()Update state when a heartbeat is sent out. This will transition out of the states that end when a heartbeat request is sent, without waiting for a response (ex.MemberState.ACKNOWLEDGINGandMemberState.LEAVING). -
onHeartbeatRequestSkipped
void onHeartbeatRequestSkipped()Transition out of theMemberState.LEAVINGstate even if the heartbeat was not sent . This will ensure that the member is not blocked onMemberState.LEAVING(best effort to send the request, without any response handling or retry logic) -
serverAssignor
- Returns:
- Server-side assignor implementation configured for the member, that will be sent out to the server to be used. If empty, then the server will select the assignor.
-
currentAssignment
- Returns:
- Current assignment for the member as received from the broker (topic IDs and partitions). This is the last assignment that the member has successfully reconciled.
-
transitionToFenced
void transitionToFenced()Transition the member to the FENCED state, where the member will release the assignment by calling the onPartitionsLost callback, and when the callback completes, it will transition toMemberState.JOININGto rejoin the group. This is expected to be invoked when the heartbeat returns a FENCED_MEMBER_EPOCH or UNKNOWN_MEMBER_ID error. -
transitionToFatal
void transitionToFatal()Transition the member to the FAILED state and update the member info as required. This is invoked when un-recoverable errors occur (ex. when the heartbeat returns a non-retriable error) -
leaveGroup
CompletableFuture<Void> leaveGroup()Release assignment and transition toMemberState.PREPARE_LEAVINGso that a heartbeat request is sent indicating the broker that the member wants to leave the group. This is expected to be invoked when the user calls the unsubscribe API.- Returns:
- Future that will complete when the callback execution completes and the heartbeat to leave the group has been sent out.
-
shouldHeartbeatNow
boolean shouldHeartbeatNow()- Returns:
- True if the member should send heartbeat to the coordinator without waiting for the interval.
-
shouldSkipHeartbeat
boolean shouldSkipHeartbeat()- Returns:
- True if the member should skip sending the heartbeat to the coordinator. This could be the case then the member is not in a group, or when it failed with a fatal error.
-
onSubscriptionUpdated
void onSubscriptionUpdated()Join the group with the updated subscription, if the member is not part of it yet. If the member is already part of the group, this will only ensure that the updated subscription is included in the next heartbeat request. Note that list of topics of the subscription is taken from the shared subscription state. -
consumerRebalanceListenerCallbackCompleted
void consumerRebalanceListenerCallbackCompleted(ConsumerRebalanceListenerCallbackCompletedEvent event) Signals that aConsumerRebalanceListenercallback has completed. This is invoked when the application thread has completed the callback and has submitted aConsumerRebalanceListenerCallbackCompletedEventto the network I/O thread. At this point, we notify the state machine that it's complete so that it can move to the next appropriate step of the rebalance process.- Parameters:
event- Event with details about the callback that was executed
-
transitionToJoining
void transitionToJoining()Transition to theMemberState.JOININGstate to attempt joining a group. -
transitionToStale
void transitionToStale()When the user stops polling the consumer and themax.poll.interval.mstimer expires, we transition the member to STALE. -
registerStateListener
Register a listener that will be called whenever the member state changes due to transitions of new data received from the server, as defined inMemberStateListener.
-