Consider moving commit method from CommitableOffset (and some others) to KafkaConsumer
See original GitHub issueDuring the discussion of https://github.com/fd4s/fs2-kafka/pull/409 I suggested that commit
method from the CommitableOffset
could be moved to the KafkaConsumer
.
CommittableOffset
feels like pure data, but it contains def commit: F[Unit]
, which is not data, but a behavior. Maybe it would be better if CommittableOffset
will not have the commit
method? Maybe it would be more natural to have it on KafkaConsumer
(like def commit(committableOffset: CommitableOffset): F[Unit]
)?
The presence of the commit
method in the CommittableOffset
adds some difficulties for creating instances like Eq
for CommittableOffset
.
All Committable...
types affected by this problem too.
As a complement to the KafkaConsumer#commit
method, we could implement commit
on the CommittableOffset
as an extension method. It will require KafkaConsumer
as an input argument, but overall I think it will help to maintain the current API as much as possible.
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (12 by maintainers)
Top GitHub Comments
We could consider adding the new methods to
KafkaConsumer
before 2.0 and deprecating the ones onCommittableX
.I’m trying to implement a version where
CommittableOffsetBatch
could contain offsets from the different consumers.Overall all looks fine.
CommittableOffset
simplified to this:And
CommittableOffsetBatch
to this:But I have some difficulties with the
commit
method implementation. Currently, thecommit
method is constructing insideKafkaConsumerActor
and added to theCommittableOffset
as a field. In the new APICommittableOffset
doesn’t have thecommit
method. Instead, it hascommitter
with the dedicatedcommit
method. The problem is thatKafkaCommit
(which is in the essence aKafkaConsumer
) is not available insideKafkaConsumerActor
. So,CommittableOffset
can’t be constructed insideKafkaConsumerActor
anymore. To fix this I see a few ways with different drawbacks:KafkaConsumerActor
some new entity, which is likeCommittableOffset
, but withoutcommitter
field. When these entities reach KafkaConsumer it enriched them and turned intoCommittableOffset
with thecommitter
field. It’s doable, but some decent amount of code should be rewritten and every batch should be traversed to create aCommittableOffset
. I’m not sure how bad is that in terms of performance.KafkaConsumer
inKafkaConsumerActor
. It could be done only with the message passing becauseKafkaConsumerActor
is created earlier than theKafkaConsumer
. It means that we will need some new actor message likeSetKafkaConsumer
which will set a mutable field insideKafkaConsumerActor
. It’s doable too but feels a bit dirty becauseKafkaConsumerActor
will need a mutable optional field which in practice will be always filled with the value.Committer
entity for thecommitter
field in theCommittableOffset
. This entity will be created beforeKafkaConsumerActor
andKafkaConsumer
inside theKafkaConsumer
constructor. It could be passed to theKafkaConsumerActor
without dirty message passing. And It could create a link between aKafkaConsumerActor
andKafkaConsumer
. With this option, we will have an extraCommitter
entity in the public API, which is not good. Also, its purpose will be exclusively technical, to overcome our internal difficulties with the sharing data betweenKafkaConsumer
andKafkaConsumerActor
.@bplommer @vlovgr wdyt? Maybe you could offer some other options to solve this issue?