Skip to content

Instantly share code, notes, and snippets.

@dehora
Created April 11, 2015 17:07
Show Gist options
  • Save dehora/0a2d9e6ad2fa5afe1483 to your computer and use it in GitHub Desktop.
Save dehora/0a2d9e6ad2fa5afe1483 to your computer and use it in GitHub Desktop.
simple 08 kafka producer in scala
package net.dehora.kafka.scala
import java.util.Properties
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
object KafkaTestProducer {
def main(args: Array[String]): Unit = {
val producer = createProducer()
(0 until 1000).foreach(i => {
producer.send(new KeyedMessage[String, String]("test", "" + i, "test-" + i))
})
}
def createProducer(): Producer[String, String] = {
val props = new Properties()
props.put("metadata.broker.list", "127.0.0.1:9092")
props.put("serializer.class", "kafka.serializer.StringEncoder")
props.put("request.required.acks", "1")
val config = new ProducerConfig(props)
new Producer[String, String](config)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment