[英]Not able to set mapper.readValuemapper.readValue(words, classOf[InboundLocation]) in jackson as showing type mismatch in scala
val conf = new SparkConf().setAppName("SimpleExample").setMaster("local[*]")
val sc = new StreamingContext(conf,Seconds(5))
val mapper = new ObjectMapper()
val kafkaconf = Map(
"zookeeper.connect" -> "localhost:2181",
"group.id" -> "test-consumer-group",
"zookeeper.connection.timeout.ms" -> "5000"
)
val lines = KafkaUtils.createStream[Array[Byte], String , DefaultDecoder , StringDecoder](
sc ,
kafkaconf,
Map("testtopickafka" -> 1) ,
StorageLevel.MEMORY_AND_DISK
)
val words : DStream[String] = lines.flatMap { case (x, y) => y.split(" ") }
val out : InboundLocation = mapper.readValue(words, classOf[InboundLocation])
// val type12 = out.getMessage_id
// print(type12)
words.print()
sc.start()
sc.awaitTermination()
You can try with following approach. 您可以尝试以下方法。
words.foreachRDD((rdd, time) => {
if (rdd.count() > 0) {
//TODO: Apply your business logic
}
})
ssc.start()
ssc.awaitTermination()
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.