带有消息avro的CreateDirectStream

时间:2019-04-18 08:39:34

标签: scala apache-kafka avro

首先,我不得不处理来自文本文件的信息: C1_4,C2_4,C1 ______ 10,01 / 12 / 2015,30 / 12 / 2015,123456789,S,12345

现在,我需要处理相同的信息,但格式为avro。我该怎么办?

在我使用此代码之前:

createDirectStream[String, String, StringDecoder, StringDecoder](ssc,
  Map("metadata.broker.list" -> brokerlist, "auto.offset.reset" ->    "smallest"),
  Set(topic))

然后我以这种方式处理了消息:

val logStream = kafkaStream.map(pair => pair._2)

logStream.foreachRDD(
  rdd => {
    val new_rdd = rdd.map(f = line => {

      val ent = line.split(Utils.COMMA_DELIMITER)(0)
      val cenReg = line.split(Utils.COMMA_DELIMITER)(1)
      .......

      .......
    })
  })

现在我正在尝试通过这种方式进行操作:

  createDirectStream[Object, Object, KafkaAvroDecoder, KafkaAvroDecoder](ssc,
  Map("metadata.broker.list" -> brokerlist, "auto.offset.reset" -> "smallest"),
  Set(topic))


Also I have to use a SchemaRegistry that the client give me.


How can I process the messages avro ?

0 个答案:

没有答案