Can someone give advices on how to convert a String
into a GenericRecord
? I would like to convert my records to avro and put them into a Kafka topic.
I used to have it as a String
(I replaced it with GenericRecord
).
def producerMethod(socket: Seq[Socket], prot: String): KafkaProducer[String, GenericRecord] =
producer(params(socket, prot))
def producerMethod(params: Map[String, String]): KafkaProducer[String, GenericRecord] =
new KafkaProducer[String, GenericRecord](params.asInstanceOf[Map[String, Object]].asJava)
I also have an apply
method, which has an iterator in it.
It iterates over strings and adds the values in a tuple.
In the end I send the data to a topic:
The results variable is a String
but I added "asInstanceOf"
result.send(new ProducerRecord[String,GenericRecord](topic,key,results.asInstanceOf[GenericRecord]))
Here is my iterator:
iterator.foreach { tuple =>
val (keyinfo, info, Worked(outinfo, _)) = tuple
val (key, results) = keyResultToString(keyinfo, info, outinfo)
result.send(new ProducerRecord[String,GenericRecord](topic,key,results.asInstanceOf[GenericRecord]))
}
Everything works, when I replace the GenericRecord back to String. But not if I would like to convert it to a GenericRecord