11.1 从 Kafka 读取数据
在模块gmall-realtime
中新建OrderApp.scala
package com.atguigu.dw.gmall.realtime.app
import com.atguigu.dw.gmall.common.constant.GmallConstant
import com.atguigu.dw.gmall.realtime.util.MyKafkaUtil
import org.apache.spark.SparkConf
import org.apache.spark.streaming.dstream.InputDStream
import org.apache.spark.streaming.{Seconds, StreamingContext}
/**
* Author lzc
* Date 2019/5/17 5:31 PM
*/
object OrderApp {
def main(args: Array[String]): Unit = {
val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("OrderApp")
val ssc = new StreamingContext(conf, Seconds(2))
val inputDSteam: InputDStream[(String, String)] = MyKafkaUtil.getKafkaStream(ssc, GmallConstant.TOPIC_ORDER)
inputDSteam.print(20)
ssc.start()
ssc.awaitTermination()
}
}