本文整理汇总了Scala中org.apache.avro.generic.GenericData.Record类的典型用法代码示例。如果您正苦于以下问题:Scala Record类的具体用法?Scala Record怎么用?Scala Record使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Record类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Main
//设置package包名称以及导入依赖的类
package com.github.dnvriend
import akka.actor.ActorSystem
import org.apache.avro.Schema
import org.apache.avro.generic.GenericData
import org.apache.avro.generic.GenericData.Record
import org.apache.kafka.clients.producer.{ KafkaProducer, ProducerRecord }
import scala.concurrent.Future
import scala.concurrent._
object Main extends App {
val system = ActorSystem()
implicit val ec = system.dispatcher
val producer = new KafkaProducer[String, Record](KafkaConfig.config)
val key = "key1"
val userSchema =
"""
|{
| "type":"record",
| "name":"myrecord",
| "fields": [
| {"name": "f1", "type":"string"}
| ]
|}
""".stripMargin
val parser = new Schema.Parser()
val schema = parser.parse(userSchema)
val avroRecord: Record = new GenericData.Record(schema)
avroRecord.put("f1", "value1")
val record = new ProducerRecord("topic1", key, avroRecord)
(for {
_ <- Future(blocking(producer.send(record).get))
_ <- system.terminate()
} yield ()).recoverWith {
case t: Throwable =>
t.printStackTrace()
system.terminate()
}
}