Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.evolutiongaming.skafka
package producer

import cats.data.NonEmptyMap as Nem
Comment thread
tobiajo marked this conversation as resolved.
import cats.effect.{Async, Deferred, Resource, Sync}
import cats.effect.implicits.*
import cats.implicits.*
import cats.{Applicative, Functor, Monad, MonadError, MonadThrow, ~>}
import com.evolutiongaming.catshelper.CatsHelper.*
import com.evolutiongaming.catshelper.{Log, MeasureDuration, ToTry}
import com.evolutiongaming.skafka.Converters.*
import com.evolutiongaming.skafka.consumer.ConsumerGroupMetadata
import com.evolutiongaming.skafka.consumer.ConsumerConverters.*
import com.evolutiongaming.skafka.producer.ProducerConverters.*
import org.apache.kafka.clients.producer.{
Callback,
Expand All @@ -33,6 +36,15 @@ trait Producer[F[_]] {

def abortTransaction: F[Unit]

/** Sends consumed offsets to the consumer group coordinator as part of the current transaction, fencing zombie
* writers by the consumer group generation (KIP-447). The `consumerGroupMetadata` must come from the input
* consumer's `groupMetadata()`; offsets become committed only if the transaction commits.
*/
def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): F[Unit]

/** @return
* Outer F[_] is about sending event (including batching if required), inner F[_] is about waiting and getting the
* result of the send operation.
Expand Down Expand Up @@ -70,6 +82,11 @@ object Producer {

def abortTransaction: F[Unit] = empty

def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): F[Unit] = empty

def send[K, V](
record: ProducerRecord[K, V]
)(implicit toBytesK: ToBytes[F, K], toBytesV: ToBytes[F, V]): F[F[RecordMetadata]] = {
Expand Down Expand Up @@ -121,6 +138,13 @@ object Producer {
blocking { producer.abortTransaction() }
}

def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): F[Unit] = {
blocking { producer.sendOffsetsToTransaction(asOffsetsAndMetadataJ(offsets), consumerGroupMetadata.asJava) }
}

def send[K, V](
record: ProducerRecord[K, V]
)(implicit toBytesK: ToBytes[F, K], toBytesV: ToBytes[F, V]): F[F[RecordMetadata]] = {
Expand Down Expand Up @@ -250,6 +274,11 @@ object Producer {
} yield r
}

def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): F[Unit] = producer.sendOffsetsToTransaction(offsets, consumerGroupMetadata)

def send[K, V](
record: ProducerRecord[K, V]
)(implicit toBytesK: ToBytes[F, K], toBytesV: ToBytes[F, V]): F[F[RecordMetadata]] = {
Expand Down Expand Up @@ -345,6 +374,11 @@ object Producer {

def abortTransaction: G[Unit] = fg(self.abortTransaction)

def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): G[Unit] = fg(self.sendOffsetsToTransaction(offsets, consumerGroupMetadata))

def send[K, V](
record: ProducerRecord[K, V]
)(implicit toBytesK: ToBytes[G, K], toBytesV: ToBytes[G, V]): G[G[RecordMetadata]] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.evolutiongaming.skafka.producer

import cats.data.NonEmptyMap as Nem
import cats.implicits.*
import cats.MonadThrow
import com.evolutiongaming.catshelper.{Log, MeasureDuration}
import com.evolutiongaming.skafka.{ClientMetric, PartitionInfo, ToBytes, Topic}
import com.evolutiongaming.skafka.{ClientMetric, OffsetAndMetadata, PartitionInfo, ToBytes, Topic, TopicPartition}
import com.evolutiongaming.skafka.consumer.ConsumerGroupMetadata
import org.apache.kafka.common.Uuid
import org.apache.kafka.common.errors.RecordTooLargeException

Expand All @@ -30,6 +32,11 @@ object ProducerLogging {

def abortTransaction: F[Unit] = producer.abortTransaction

def sendOffsetsToTransaction(
offsets: Nem[TopicPartition, OffsetAndMetadata],
consumerGroupMetadata: ConsumerGroupMetadata
): F[Unit] = producer.sendOffsetsToTransaction(offsets, consumerGroupMetadata)

def send[K, V](
record: ProducerRecord[K, V]
)(implicit toBytesK: ToBytes[F, K], toBytesV: ToBytes[F, V]): F[F[RecordMetadata]] = {
Expand Down