Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (22 sloc) 882 Bytes
package workers
import org.apache.kafka.clients.producer.ProducerRecord
import play.api.{Configuration, Environment}
import play.api.inject.guice.GuiceApplicationBuilder
import services.Kafka
import scala.concurrent.duration._
import scala.util.Random
// Every 500 millis send a random number to Kafka
object RandomNumbers extends App {
val config = Configuration.load(Environment.simple())
val app = GuiceApplicationBuilder(configuration = config).build()
val kafka = app.injector.instanceOf[Kafka]
val topic = kafka.maybePrefix.getOrElse("") + "RandomNumbers"
val tickSource = Source.tick(Duration.Zero, 500.milliseconds, Unit).map(_ => Random.nextInt().toString) { kafkaSink =>
.map(new ProducerRecord[String, String](topic, _))