Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save holgerbrandl/cc56f2262ffaf0fd4d05df2c5e934a2e to your computer and use it in GitHub Desktop.
Save holgerbrandl/cc56f2262ffaf0fd4d05df2c5e934a2e to your computer and use it in GitHub Desktop.
Example to illustrate issue when running kafka code with kotlin
#!/usr/bin/env kscript
@file:DependsOn("org.apache.kafka:kafka-clients:1.1.0")
import java.util.Properties
import org.apache.kafka.clients.producer.KafkaProducer
import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.StringSerializer
val properties = Properties()
properties.setProperty("bootstrap.servers", "localhost:9092")
properties.setProperty("topic", "test")
properties.setProperty("acks", "all")
properties.setProperty("retries", "0")
properties.setProperty("batch.size", "16384")
properties.setProperty("linger.ms", "1")
properties.setProperty("buffer.memory", "33554432")
properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
val producer = KafkaProducer<String, String>(properties)
producer.send(ProducerRecord(properties.getProperty("topic"), "exampleKey", "exampleValue"))
producer.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment