kafka流处理器Api反序列化avro记录

时间:2018-09-26 05:42:45

标签: java apache-kafka avro apache-kafka-streams

我正在从Kafka流式传输实时数据。但是数据为Avro格式。无法反序列化为Json。 Iam使用Kafka Stream低级处理器API。如何反序列化Avro记录?

def orderStreamData(builder: KStreamBuilder, inTopic: String, outTopic: String): TopologyBuilder = {
    builder
      .addSource("source1", stringDe, stringDe, inTopic)//adding source topic
      //now adding processor class using ProcessSupplier
      .addProcessor("order", new ProcessorSupplier[String, String] {
      override def get(): Processor[String, String] = new ProcessorImpl
    }, "source1")
      //adding local state store for stateful operations
      .addStateStore(Stores.create("tester").withStringKeys.withStringValues.inMemory.build, "order")
      //adding destination topic for the processed data to go
      .addSink("sink", outTopic, stringSer, stringSer, "order")
  }

class ProcessorImpl extends AbstractProcessor[String, String]{

  var keyValueStore: KeyValueStore[String, String] = _
  var processorContext: ProcessorContext = _

  override def init(context: ProcessorContext): Unit = {
    processorContext = context
    processorContext.schedule(10000L)
    keyValueStore = processorContext.getStateStore("tester").asInstanceOf[KeyValueStore[String, String]]
    Objects.requireNonNull(keyValueStore, "State Store can't be null")
  }
/**
  * here logic is implemented
  * every value for a key must be greater than the previous value
  * */
  override def process(key: String, value: String): Unit = {
    //accessing local state store for last value saved for this key

  }
}

1 个答案:

答案 0 :(得分:0)

DateTimeField

}