All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.evolutiongaming.kafka.journal.KafkaProducerOf.scala Maven / Gradle / Ivy

The newest version!
package com.evolutiongaming.kafka.journal

import cats.Monad
import cats.effect._
import com.evolutiongaming.skafka.producer.{ProducerConfig, ProducerMetrics, ProducerOf}
import com.evolutiongaming.smetrics.MeasureDuration

import scala.concurrent.ExecutionContext


trait KafkaProducerOf[F[_]] {

  def apply(config: ProducerConfig): Resource[F, KafkaProducer[F]]
}

object KafkaProducerOf {

  def apply[F[_]](implicit F: KafkaProducerOf[F]): KafkaProducerOf[F] = F


  def apply[F[_] : Effect : ContextShift : MeasureDuration](
    blocking: ExecutionContext,
    metrics: Option[ProducerMetrics[F]] = None
  ): KafkaProducerOf[F] = {

    val producerOf = ProducerOf(blocking, metrics)
    apply(producerOf)
  }


  def apply[F[_] : Monad](producerOf: ProducerOf[F]): KafkaProducerOf[F] = {
    config: ProducerConfig => {
      for {
        producer <- producerOf(config)
      } yield {
        KafkaProducer(producer)
      }
    }
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy