-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KafkaConsumer.commitAsync
#126
KafkaConsumer.commitAsync
#126
Conversation
That make sense to have async method, however it is especially a problem with fixed poll interval. If commits are often and poll interval is adaptive, that should not be a problem (unless it is a rare operation). |
@felixschlegel Can you elaborate the use-case for the async commit here a bit more? When would you want to use this while doing manual commit management? |
Motivation: Having `KafkaConsumer.commitSync` be `async` is not always convenient as it suspends the `KafkaConsumer.messages` read loop and can therefore lower throughput. This PR introduces a new method `KafkaConsumer.commitAsync` that allows users who don't care about the result of the `commit` to commit in a "fire-and-forget" manner. Modifications: * new method `KafkaConsumer.commitAsync` * rename `KafkaConsumer.StateMachine.commitSync` to `KafkaConsumer.StateMachine.commit` to serve both `commitSync` and `commitAsync` * add new test for `KafkaConsumer.commitAsync`
0324457
to
0fa9862
Compare
I don't know if this is the answer you're looking for, but generally manual commits allow the user to decide when a message is marked as processed. The problem with With In the worst case, if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining @felixschlegel. One last comment
What about naming these two methods commit() async throws
and triggerCommit() throws
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixschlegel Can you check why the CI is failing?
/// | ||
/// - Parameter message: Last received message that shall be marked as read. | ||
/// - Throws: A ``KafkaError`` if scheduling the commit failed. | ||
func commitAsync(_ message: KafkaConsumerMessage) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we align the name here with triggerCommit
and commit
please
46098d3
to
f294751
Compare
Sources/Kafka/KafkaConsumer.swift
Outdated
@@ -367,17 +369,46 @@ public final class KafkaConsumer: Sendable, Service { | |||
/// - Parameters: | |||
/// - message: Last received message that shall be marked as read. | |||
/// - Throws: A ``KafkaError`` if committing failed. | |||
public func triggerCommit(_ message: KafkaConsumerMessage) throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay sorry for the bike shedding but we probably should call this scheduleCommit
which has a bit better semantics. Can you rename the public and internal methods?
f294751
to
dd7e233
Compare
Modifications: * `KafkaConsumer`: * rename `commitSync(_:)` -> `commit(_:)` * rename `commitAsync(_:)` -> `scheduleCommit(_:)` * `RDKafkaClient`: * rename `commitSync(_:)` -> `commit(_:)` * rename `commitAsync(_:)` -> `scheduleCommit(_:)`
dd7e233
to
6847dda
Compare
Motivation:
Having
KafkaConsumer.commitSync
beasync
is not always convenient asit suspends the
KafkaConsumer.messages
read loop and can thereforelower throughput.
This PR introduces a new method
KafkaConsumer.commitAsync
that allowsusers who don't care about the result of the
commit
to commit in a"fire-and-forget" manner.
Modifications:
KafkaConsumer.commitAsync
KafkaConsumer.StateMachine.commitSync
toKafkaConsumer.StateMachine.commit
to serve bothcommitSync
andcommitAsync
KafkaConsumer.commitAsync