I am trying to read avro kafka topic in Scala with case class:
val senv = StreamExecutionEnvironment.getExecutionEnvironment
val kafkaSourceTopic = "device_logs"
val kafkaBrokers = "localhost:9092"
val properties = new Properties()
properties.setProperty("bootstrap.servers", kafkaBrokers)
properties.setProperty("group.id", "flink_app_avro")
case class DeviceData(
custom_fields: String,
upload_time: Long,
build: String,
device_id: String,
log_version: Int
)
val consumer = new FlinkKafkaConsumer[DeviceData](kafkaSourceTopic, new AvroDeserializationSchema[DeviceData](classOf[DeviceData]), properties)
val stream = senv.addSource(consumer)
Got this error when running the code in flink-scala-shell:
scala> val consumer = new FlinkKafkaConsumer[DeviceData](kafkaSourceTopic, new AvroDeserializationSchema[DeviceData](classOf[DeviceData], null), properties)
<console>:92: error: constructor AvroDeserializationSchema in class AvroDeserializationSchema cannot be accessed in object $iw
val consumer = new FlinkKafkaConsumer[DeviceData](kafkaSourceTopic, new AvroDeserializationSchema[DeviceData](classOf[DeviceData], null), properties)
How to read avro topic with AvroDeserializationSchema in Scala? Thanks.
You can't simply create a case class and tell Flink to parse avro to that automatically. Avro is a binary format and You need to know schema which You will use to parse the records. Due to that, You can either:
AvroDeserializationSchema
for GenericRecord
using AvroDeserializationSchema.forGeneric
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.