@@ -101,7 +101,8 @@ sealed abstract class CommittableOffsetBatch[F[_]] {
101101}
102102
103103object CommittableOffsetBatch {
104- private [kafka] def apply [F [_]](
104+
105+ private [kafka] def ofMultiTopic [F [_]](
105106 offsets : Map [TopicPartition , OffsetAndMetadata ],
106107 consumerGroupIds : Set [String ],
107108 consumerGroupIdsMissing : Boolean ,
@@ -114,15 +115,15 @@ object CommittableOffsetBatch {
114115
115116 new CommittableOffsetBatch [F ] {
116117 override def updated (that : CommittableOffset [F ]): CommittableOffsetBatch [F ] =
117- CommittableOffsetBatch (
118+ CommittableOffsetBatch .ofMultiTopic (
118119 _offsets.updated(that.topicPartition, that.offsetAndMetadata),
119120 that.consumerGroupId.fold(_consumerGroupIds)(_consumerGroupIds + _),
120121 _consumerGroupIdsMissing || that.consumerGroupId.isEmpty,
121122 _commitMap
122123 )
123124
124125 override def updated (that : CommittableOffsetBatch [F ]): CommittableOffsetBatch [F ] =
125- CommittableOffsetBatch (
126+ CommittableOffsetBatch .ofMultiTopic (
126127 _offsets ++ that.offsets,
127128 _consumerGroupIds ++ that.consumerGroupIds,
128129 _consumerGroupIdsMissing || that.consumerGroupIdsMissing,
@@ -140,7 +141,7 @@ object CommittableOffsetBatch {
140141
141142 override def commit : F [Unit ] =
142143 if (_consumerGroupIdsMissing)
143- F .raiseError(ConsumerGroupException (consumerGroupIds))
144+ ApplicativeThrow [ F ] .raiseError(ConsumerGroupException (consumerGroupIds))
144145 else {
145146 offsetsByTopic
146147 .map {
@@ -149,7 +150,7 @@ object CommittableOffsetBatch {
149150 .getOrElse[Map [TopicPartition , OffsetAndMetadata ] => F [Unit ]](
150151 topicName,
151152 _ =>
152- F .raiseError(
153+ ApplicativeThrow [ F ] .raiseError(
153154 new RuntimeException (s " Cannot perform commit for topic: $topicName" )
154155 )
155156 )
@@ -164,17 +165,43 @@ object CommittableOffsetBatch {
164165 }
165166 }
166167
167- def one [F [_]: ApplicativeThrow ](
168- topicPartition : TopicPartition ,
169- offsetAndMetadata : OffsetAndMetadata ,
170- consumerGroupId : Option [String ],
168+ @ deprecated(" Use CommittableOffsetBatch.apply with commitMap instead." , since = " 2.5.1" )
169+ private [kafka] def apply [F [_]](
170+ offsets : Map [TopicPartition , OffsetAndMetadata ],
171+ consumerGroupIds : Set [String ],
172+ consumerGroupIdsMissing : Boolean ,
171173 commit : Map [TopicPartition , OffsetAndMetadata ] => F [Unit ]
174+ )(implicit F : ApplicativeError [F , Throwable ]): CommittableOffsetBatch [F ] =
175+ ofMultiTopic[F ](
176+ offsets,
177+ consumerGroupIds,
178+ consumerGroupIdsMissing,
179+ offsets.headOption
180+ .map(_._1.topic())
181+ .map(topicName => Map (topicName -> commit))
182+ .getOrElse(Map .empty)
183+ )
184+
185+ /**
186+ * A [[CommittableOffsetBatch ]] which does include only one offset for a single topic.
187+ *
188+ * @tparam F effect type to use to perform the commit effect
189+ * @return A [[CommittableOffsetBatch ]] which does include only one offset for a single topic.
190+ *
191+ * @see [[CommittableOffsetBatch#fromFoldable ]]
192+ * @see [[CommittableOffsetBatch#fromFoldableOption ]]
193+ */
194+ def one [F [_]: ApplicativeThrow ](
195+ committableOffset : CommittableOffset [F ]
172196 ): CommittableOffsetBatch [F ] =
173- CommittableOffsetBatch (
174- Map (topicPartition -> offsetAndMetadata),
175- consumerGroupId.toSet,
176- consumerGroupId.isEmpty,
177- Map (topicPartition.topic() -> commit)
197+ CommittableOffsetBatch .ofMultiTopic[F ](
198+ Map (committableOffset.topicPartition -> committableOffset.offsetAndMetadata),
199+ committableOffset.consumerGroupId.toSet,
200+ committableOffset.consumerGroupId.isEmpty,
201+ Map (
202+ committableOffset.topicPartition
203+ .topic() -> Map (committableOffset.topicPartition.topic() -> committableOffset.commit)
204+ )
178205 )
179206
180207 /**
@@ -238,7 +265,7 @@ object CommittableOffsetBatch {
238265 }
239266 }
240267
241- CommittableOffsetBatch (
268+ CommittableOffsetBatch .ofMultiTopic (
242269 offsetsMap,
243270 consumerGroupIds,
244271 consumerGroupIdsMissing,
@@ -290,7 +317,7 @@ object CommittableOffsetBatch {
290317 if (offsets.isEmpty || offsets.exists(_.isEmpty))
291318 CommittableOffsetBatch .empty[F ]
292319 else
293- CommittableOffsetBatch (
320+ CommittableOffsetBatch .ofMultiTopic (
294321 offsetsMap,
295322 consumerGroupIds,
296323 consumerGroupIdsMissing,
0 commit comments