val ssc = StreamingContext.getOrCreate(checkpointDirectory, () => { val topics = "logTopic" val brokers = "master:9092,slave1:9092" val sparkConf = new SparkConf().setAppName("uv").setMaster("local[2]") val ssc = new StreamingContext(sparkConf, Seconds(2)) ssc.checkpoint(checkpointDirectory) //create direct kafka stream with brokers and topics /* 直接消费是不经过zookeeper的,所以这时候你就要告诉我kafka的地址,而不是zookeeper的地址里 */ val topicSet = topics.split(",").toSet val kafkaParams = Map[String, String]("metadata.broker.list" -> brokers) //stringdecoder表示传的消息是字符串类型的 val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder]( ssc, kafkaParams, topicSet ) computeUV(messages) ssc })
spark的streamingcontext的另一种创建方式
最新推荐文章于 2019-10-26 11:11:44 发布