Class CommitRequestManager

java.lang.Object
org.apache.kafka.clients.consumer.internals.CommitRequestManager
All Implemented Interfaces:
MemberStateListener, RequestManager

public class CommitRequestManager extends Object implements RequestManager, MemberStateListener
  • Constructor Details

  • Method Details

    • poll

      public NetworkClientDelegate.PollResult poll(long currentTimeMs)
      Poll for the OffsetFetchRequest and OffsetCommitRequest request if there's any. The function will also try to autocommit the offsets, if feature is enabled.
      Specified by:
      poll in interface RequestManager
      Parameters:
      currentTimeMs - The current system time at which the method was called; useful for determining if time-sensitive operations should be performed
    • signalClose

      public void signalClose()
      Description copied from interface: RequestManager
      Signals the request manager that the consumer is closing to prepare for the proper actions to be taken.
      Specified by:
      signalClose in interface RequestManager
    • maximumTimeToWait

      public long maximumTimeToWait(long currentTimeMs)
      Returns the delay for which the application thread can safely wait before it should be responsive to results from the request managers. For example, the subscription state can change when heartbeats are sent, so blocking for longer than the heartbeat interval might mean the application thread is not responsive to changes.
      Specified by:
      maximumTimeToWait in interface RequestManager
      Parameters:
      currentTimeMs - The current system time at which the method was called; useful for determining if time-sensitive operations should be performed
      Returns:
      The maximum delay in milliseconds
    • maybeAutoCommitAllConsumedAsync

      public CompletableFuture<Void> maybeAutoCommitAllConsumedAsync()
      If auto-commit is enabled, this will generate a commit offsets request for all assigned partitions and their current positions. Note on auto-commit timers: this will reset the auto-commit timer to the interval before issuing the async commit, and when the async commit completes, it will reset the auto-commit timer with the exponential backoff if the request failed with a retriable error.
      Returns:
      Future that will complete when a response is received for the request, or a completed future if no request is generated.
    • maybeAutoCommitAllConsumedNow

      public CompletableFuture<Void> maybeAutoCommitAllConsumedNow(Optional<Long> expirationTimeMs, boolean retryOnStaleEpoch)
      Commit consumed offsets if auto-commit is enabled. Retry while the timer is not expired, until the request succeeds or fails with a fatal error.
    • addOffsetCommitRequest

      public CompletableFuture<Void> addOffsetCommitRequest(Map<org.apache.kafka.common.TopicPartition,OffsetAndMetadata> offsets, Optional<Long> expirationTimeMs, boolean retryOnStaleEpoch)
      Handles CommitApplicationEvent. It creates an CommitRequestManager.OffsetCommitRequestState and enqueue it to send later.
    • addOffsetFetchRequest

      public CompletableFuture<Map<org.apache.kafka.common.TopicPartition,OffsetAndMetadata>> addOffsetFetchRequest(Set<org.apache.kafka.common.TopicPartition> partitions, long expirationTimeMs)
      Handles FetchCommittedOffsetsApplicationEvent. It creates an CommitRequestManager.OffsetFetchRequestState and enqueue it to send later.
    • updateAutoCommitTimer

      public void updateAutoCommitTimer(long currentTimeMs)
    • onMemberEpochUpdated

      public void onMemberEpochUpdated(Optional<Integer> memberEpoch, Optional<String> memberId)
      Update latest member ID and epoch used by the member.
      Specified by:
      onMemberEpochUpdated in interface MemberStateListener
      Parameters:
      memberEpoch - New member epoch received. To be included in the new request.
      memberId - Current member ID. To be included in the new request.
    • autoCommitEnabled

      public boolean autoCommitEnabled()
      Returns:
      True if auto-commit is enabled as defined in the config ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG
    • resetAutoCommitTimer

      public void resetAutoCommitTimer()
      Reset the auto-commit timer to the auto-commit interval, so that the next auto-commit is sent out on the interval starting from now. If auto-commit is not enabled this will perform no action.
    • resetAutoCommitTimer

      public void resetAutoCommitTimer(long retryBackoffMs)
      Reset the auto-commit timer to the provided time (backoff), so that the next auto-commit is sent out then. If auto-commit is not enabled this will perform no action.
    • drainPendingOffsetCommitRequests

      public NetworkClientDelegate.PollResult drainPendingOffsetCommitRequests()
      Drains the inflight offsetCommits during shutdown because we want to make sure all pending commits are sent before closing.