Last active
February 4, 2020 19:56
-
-
Save rogerzxu/e804fc36b0aca4e3b9a57e7a0a01f0f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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