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 Details

      • groupId

        String groupId()
        Returns:
        Group ID of the consumer group the member is part of (or wants to be part of).
      • groupInstanceId

        Optional<String> 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.ACKNOWLEDGING and MemberState.LEAVING).
      • onHeartbeatRequestSkipped

        void onHeartbeatRequestSkipped()
        Transition out of the MemberState.LEAVING state even if the heartbeat was not sent . This will ensure that the member is not blocked on MemberState.LEAVING (best effort to send the request, without any response handling or retry logic)
      • serverAssignor

        Optional<String> 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

        Map<org.apache.kafka.common.Uuid,SortedSet<Integer>> 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 to MemberState.JOINING to 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 to MemberState.PREPARE_LEAVING so 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 a ConsumerRebalanceListener callback has completed. This is invoked when the application thread has completed the callback and has submitted a ConsumerRebalanceListenerCallbackCompletedEvent to 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 the MemberState.JOINING state to attempt joining a group.
      • transitionToStale

        void transitionToStale()
        When the user stops polling the consumer and the max.poll.interval.ms timer expires, we transition the member to STALE.
      • registerStateListener

        void registerStateListener(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 in MemberStateListener.