package com.ws.streaming
import java.util.Properties
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
/**
* kafka生产者
*/
object ProducerDemo {
def main(args: Array[String]): Unit = {
val prop = new Properties()
prop.put("metadata.broker.list","hadoop-01:9092,hadoop-02:9092,hadoop-03:9092")
prop.setProperty("serializer.class","kafka.serializer.StringEncoder")
val config = new ProducerConfig(prop)
val producer = new Producer[String,String](config)
for (i <- 1 to 1000){
//参数1:指定topic ,参数2:写入的数据
Thread.sleep(5000)
producer.send(new KeyedMessage[String,String]("ws","good night "+i))
}
}
}
kafka生产者
最新推荐文章于 2021-01-20 00:08:15 发布