【发布时间】:2018-08-19 04:37:57
【问题描述】:
我需要以下情况的帮助:
我将从 Kafka 获取以下 JSON 格式的数据以触发流式传输
{"id" : 1 , "data" : "AFGH00101219"}
{"id" : 2 , "data" : "AFGH00101215"}
{"id" : 2 , "data" : "AFGH00101216"}
{"id" : 3 , "data" : "AFGH00101218"}
val messages= KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topics)
现在我想处理消息中的每条 JSON 记录,然后每条记录依次返回一组记录。请给我一些想法来完成以下任务。
val output = messages.map(row =>
{
//here I will get each json record. My doubt is how to extract id and data
//filed values from row and store it into variables.
//Here I need to decode the data filed value which is in hexa decimal format
//to decimal format.
}
提前致谢。如果问题不清楚,请告诉我。
【问题讨论】:
-
您可以实现自己的实际将 JSON 解析为对象的方法,而不是使用 StringDecoder
标签: scala apache-spark apache-kafka spark-streaming