Skip to content

Instantly share code, notes, and snippets.

@rogerzxu
Last active February 4, 2020 19:56
Show Gist options
  • Save rogerzxu/e804fc36b0aca4e3b9a57e7a0a01f0f1 to your computer and use it in GitHub Desktop.
Save rogerzxu/e804fc36b0aca4e3b9a57e7a0a01f0f1 to your computer and use it in GitHub Desktop.
name := "fs2-kafka-test"
version := "0.1"
scalaVersion := "2.12.10"
libraryDependencies ++= Seq(
"com.ovoenergy" %% "fs2-kafka" % "0.20.2",
"org.scalatest" %% "scalatest" % "3.0.8" % Test,
)
scalacOptions ++= Seq(
"-language:higherKinds",
"-feature",
"-deprecation",
"-unchecked",
"-Ypartial-unification"
)
import org.scalatest.WordSpec
import fs2.kafka._
import cats.effect._
import cats.implicits._
class ProducerSpec extends WordSpec {
"Producer" must {
"work" in {
implicit val iocs = IO.contextShift(scala.concurrent.ExecutionContext.global)
val producerSettings = ProducerSettings[IO, String, String].withBootstrapServers("localhost:9092")
producerStream(producerSettings)
.map { producer =>
val record = ProducerRecords.one(
ProducerRecord[String, String](
topic = "pizza-events",
key = "key",
value = "message"
)
)
producer.produce(record).flatten
}
.compile
.lastOrError
.flatten
.unsafeRunSync()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment