Created
June 18, 2018 08:07
-
-
Save holgerbrandl/cc56f2262ffaf0fd4d05df2c5e934a2e to your computer and use it in GitHub Desktop.
Example to illustrate issue when running kafka code with kotlin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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