Skip to content

Instantly share code, notes, and snippets.

@NeQuissimus
Created April 28, 2018 23:52
Show Gist options
  • Save NeQuissimus/d3826d5a1a167cf784120011e27c22ab to your computer and use it in GitHub Desktop.
Save NeQuissimus/d3826d5a1a167cf784120011e27c22ab to your computer and use it in GitHub Desktop.
Generate Kafka sample messages
import $ivy.`io.monix::monix-kafka-1x:1.0.0-RC1`
import monix.execution.Scheduler.Implicits.{ global => scheduler }
import monix.kafka._
import scala.concurrent.duration._
val producerCfg = KafkaProducerConfig.default.copy(
bootstrapServers = List("127.0.0.1:9092")
)
val producer = KafkaProducer[String,String](producerCfg, scheduler)
val messages = scheduler.scheduleWithFixedDelay(1.second, 1.second) { producer.send("test", "hello", s"${System.nanoTime}").runAsync }
// messages.cancel will stop producing the messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment