Skip to content

Commit 3601e49

Browse files
committed
Add singleTopic in CommittableOffsetBatch
1 parent 7b8f807 commit 3601e49

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

modules/core/src/main/scala/fs2/kafka/CommittableOffsetBatch.scala

+33-2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ sealed abstract class CommittableOffsetBatch[F[_]] {
101101
}
102102

103103
object CommittableOffsetBatch {
104+
104105
private[kafka] def apply[F[_]](
105106
offsets: Map[TopicPartition, OffsetAndMetadata],
106107
consumerGroupIds: Set[String],
@@ -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,6 +165,36 @@ object CommittableOffsetBatch {
164165
}
165166
}
166167

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,
173+
commit: Map[TopicPartition, OffsetAndMetadata] => F[Unit]
174+
)(implicit F: ApplicativeError[F, Throwable]): CommittableOffsetBatch[F] =
175+
apply[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+
* @param topicPartition Topic partition information
189+
* @param offsetAndMetadata Offset and metadata
190+
* @param consumerGroupId Consumer group id
191+
* @param commit effect to perform to commit this offset
192+
* @tparam F effect type to use to perform the commit effect
193+
* @return A [[CommittableOffsetBatch]] which does include only one offset for a single topic.
194+
*
195+
* @see [[CommittableOffsetBatch#fromFoldable]]
196+
* @see [[CommittableOffsetBatch#fromFoldableOption]]
197+
*/
167198
def one[F[_]: ApplicativeThrow](
168199
topicPartition: TopicPartition,
169200
offsetAndMetadata: OffsetAndMetadata,

0 commit comments

Comments
 (0)