大家好:
sparkStream中作为kafka的生产者,将某个文件中的数据打到kafka中。
package Traffic
import java.util.Properties
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import org.apache.spark.{SparkConf, SparkContext}
import org.codehaus.jettison.json.JSONObject
/**
* Created by Administrator on 2017/10/14.
* 功能:SparkStream作为kafka的生产者,将制定文件数据打到kafka中
*
*/
object KafkaEventProducer {
def main(args: Array[String]): Unit = {
//创建topic
val topic="car_event"
val brokers="192.168.17.108:9092"
val props=new Properties()
//把broker put进去
props.put("metadata.broker.list",brokers)
//把kafka编译器放进去
props.put("serializer.class","kafka.serializer.StringEncoder")
//配置kafka的config(配置)
val kafkaconfig=new ProducerConfig(props)
val producer=new Producer[String,String](kafkaconfig)
//配置spark的config
val conf=new SparkConf().setA