Created
April 11, 2015 17:07
-
-
Save dehora/0a2d9e6ad2fa5afe1483 to your computer and use it in GitHub Desktop.
simple 08 kafka producer in scala
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
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