1

I have some code that is receiving fully formed Kafka ConnectRecords. I would like to take those records, and convert them to Avro's GenericRecord. I imagine a utility must exist to do this. I want to do something really simple:

ConnectRecord myInput = ... // some connect record

GenericRecord myAvroInput = MyUtility.convertKafkaToAvro(myInput);

Or perhaps:

ConnectRecord myInput = ... // some connect record

GenericRecord myAvroInput = MyUtility.convertKafkaToAvro(myInput.value(), myInput.valueSchema());

Is there a utility that can help me do this?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Pablo
  • 10,425
  • 1
  • 44
  • 67
  • This is what the Converter interface is for. You shouldn't need to do this within a Connect task, though, but are you using Schema Registry? – OneCricketeer Oct 02 '19 at 18:59
  • No, I am repurposing a Kafka connector's code to run outside of Kafka connect, and publish to a different data source. How can I use the AvroConverter? I can't find artifacts for it on Maven... – Pablo Oct 02 '19 at 19:32
  • `io.confluent:kafka-connect-avro-converter:5.3.1` And you need to add a Repo https://docs.confluent.io/current/clients/install.html#java then `fromConnectData` will return a `byte[]` which I believe is serialized Avro https://github.com/confluentinc/schema-registry/blob/master/avro-converter/src/main/java/io/confluent/connect/avro/AvroConverter.java#L78-L80 w – OneCricketeer Oct 02 '19 at 19:46

0 Answers0