Class CommitRequestManager
java.lang.Object
org.apache.kafka.clients.consumer.internals.CommitRequestManager
- All Implemented Interfaces:
MemberStateListener,RequestManager
-
Constructor Summary
ConstructorsConstructorDescriptionCommitRequestManager(org.apache.kafka.common.utils.Time time, org.apache.kafka.common.utils.LogContext logContext, SubscriptionState subscriptions, ConsumerConfig config, CoordinatorRequestManager coordinatorRequestManager, String groupId, Optional<String> groupInstanceId) -
Method Summary
Modifier and TypeMethodDescriptionaddOffsetCommitRequest(Map<org.apache.kafka.common.TopicPartition, OffsetAndMetadata> offsets, Optional<Long> expirationTimeMs, boolean retryOnStaleEpoch) HandlesCommitApplicationEvent.CompletableFuture<Map<org.apache.kafka.common.TopicPartition, OffsetAndMetadata>> addOffsetFetchRequest(Set<org.apache.kafka.common.TopicPartition> partitions, long expirationTimeMs) booleanDrains the inflight offsetCommits during shutdown because we want to make sure all pending commits are sent before closing.longmaximumTimeToWait(long currentTimeMs) Returns the delay for which the application thread can safely wait before it should be responsive to results from the request managers.If auto-commit is enabled, this will generate a commit offsets request for all assigned partitions and their current positions.maybeAutoCommitAllConsumedNow(Optional<Long> expirationTimeMs, boolean retryOnStaleEpoch) Commit consumed offsets if auto-commit is enabled.voidonMemberEpochUpdated(Optional<Integer> memberEpoch, Optional<String> memberId) Update latest member ID and epoch used by the member.poll(long currentTimeMs) Poll for theOffsetFetchRequestandOffsetCommitRequestrequest if there's any.voidReset the auto-commit timer to the auto-commit interval, so that the next auto-commit is sent out on the interval starting from now.voidresetAutoCommitTimer(long retryBackoffMs) Reset the auto-commit timer to the provided time (backoff), so that the next auto-commit is sent out then.voidSignals the request manager that the consumer is closing to prepare for the proper actions to be taken.voidupdateAutoCommitTimer(long currentTimeMs) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.kafka.clients.consumer.internals.RequestManager
pollOnClose
-
Constructor Details
-
CommitRequestManager
public CommitRequestManager(org.apache.kafka.common.utils.Time time, org.apache.kafka.common.utils.LogContext logContext, SubscriptionState subscriptions, ConsumerConfig config, CoordinatorRequestManager coordinatorRequestManager, String groupId, Optional<String> groupInstanceId)
-
-
Method Details
-
poll
Poll for theOffsetFetchRequestandOffsetCommitRequestrequest if there's any. The function will also try to autocommit the offsets, if feature is enabled.- Specified by:
pollin interfaceRequestManager- 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:RequestManagerSignals the request manager that the consumer is closing to prepare for the proper actions to be taken.- Specified by:
signalClosein interfaceRequestManager
-
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:
maximumTimeToWaitin interfaceRequestManager- 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
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) HandlesCommitApplicationEvent. It creates anCommitRequestManager.OffsetCommitRequestStateand 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) HandlesFetchCommittedOffsetsApplicationEvent. It creates anCommitRequestManager.OffsetFetchRequestStateand enqueue it to send later. -
updateAutoCommitTimer
public void updateAutoCommitTimer(long currentTimeMs) -
onMemberEpochUpdated
Update latest member ID and epoch used by the member.- Specified by:
onMemberEpochUpdatedin interfaceMemberStateListener- 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
Drains the inflight offsetCommits during shutdown because we want to make sure all pending commits are sent before closing.
-