Skip to content

Instantly share code, notes, and snippets.

@s4kibs4mi
Created May 28, 2019 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s4kibs4mi/cf45c7e51d43f1fdc0372af8ccccb83d to your computer and use it in GitHub Desktop.
Save s4kibs4mi/cf45c7e51d43f1fdc0372af8ccccb83d to your computer and use it in GitHub Desktop.
import org.apache.kafka.clients.producer.*
import java.util.*
import org.apache.kafka.common.serialization.StringSerializer
import java.lang.Exception
fun main(args: Array<String>) {
val props = Properties()
props[ProducerConfig.BOOTSTRAP_SERVERS_CONFIG] = "localhost:9092"
props[ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java.name
props[ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java.name
val producer = KafkaProducer<Int, String>(props)
producer.send(ProducerRecord("users.notification",
0, Calendar.getInstance().timeInMillis, null, "hello"), object : Callback {
override fun onCompletion(metadata: RecordMetadata?, exception: Exception?) {
println("Send Complete")
}
})
Thread.sleep(120 * 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment