Skip to content

Instantly share code, notes, and snippets.

@gavinwhyte
Created October 6, 2017 10:39
Show Gist options
  • Save gavinwhyte/2438ded53080f763546e377c0741fc2b to your computer and use it in GitHub Desktop.
Save gavinwhyte/2438ded53080f763546e377c0741fc2b to your computer and use it in GitHub Desktop.
object ProducerExample extends App {
import java.util.Properties
import org.apache.kafka.clients.producer._
val props = new Properties()
props.put("bootstrap.servers", "localhost:9092")
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
val producer = new KafkaProducer[String, String](props)
val TOPIC="test"
for(i<- 1 to 50){
val record = new ProducerRecord(TOPIC, "key", s"hello $i")
producer.send(record)
}
val record = new ProducerRecord(TOPIC, "key", "the end "+new java.util.Date)
producer.send(record)
producer.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment