Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Streaming and kafka updateStateBykey ()

Shulou Source: shulou.com Published: 2022-06-03 07:39:53 11月23日 Update

object H extends App{ val conf=new SparkConf().setMaster("local[2]").setAppName("hello") val ss=new StreamingContext(conf,Seconds(5)) val kafkaParams=Map[String,String]("metadata.broker.list"->"myhadoop1:9092") ss.checkpoint("hdfs://myhadoop1:8020/data") val topic=Set[String]("wordcount1") //kafka val lines=KafkaUtils.createDirectStream[String,String,StringDecoder,StringDecoder](ss,kafkaParams,topic) lines.flatMap(_._ 2.split(" ")).map((_,1)).updateStateByKey((seqs:Seq[Int],option:Option[Int])=>{ var oldValue=option.getOrElse(0) for(seq

Tags: Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Shulou Tech Info Redmi Shulou Technology