Hi does anyone have a link to a walkthrough or exa...
# troubleshooting
o
Hi does anyone have a link to a walkthrough or example on how to consume from a confluent topic using avro messages in a java flink task?
r
@Ole Bille We have solved this by implementing our custom
KafkaDeserializationSchema
Copy code
import com.sksamuel.avro4s.{AvroSchema, RecordFormat}

private lazy val avroRecordDeserializationSchema = ConfluentRegistryAvroDeserializationSchema.forGeneric(avroSchema, schemaRegistryUrl)
       

 val genericRecord = avroRecordDeserializationSchema.deserialize(consumerRecord.value())
        Some(recordFormat.from(genericRecord))
We are using
sksamuel.avro4s
library. Hope this helps πŸ™Œ
v
@Ole Bille
Copy code
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.Schema;
import org.apache.flink.formats.avro.registry.confluent.ConfluentRegistryAvroDeserializationSchema;
import org.apache.flink.formats.avro.registry.confluent.ConfluentRegistryAvroSerializationSchema;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.connector.kafka.source.KafkaSource;

import java.util.Properties;
import java.util.HashMap;
import java.util.Map;

String schemaString = "Copied schema from confluent cloud"
Schema schema = new Schema.Parser().parse(schemaString);

String schemaRegistryUrl = "url";

MapString, String schemaProps = new HashMap<>();
schemaProps.put("basic.auth.user.info", "XXXX");

KafkaSourceGenericRecord source = KafkaSource.GenericRecordbuilder()
        .setBootstrapServers("SERVER")
        .setTopics("TOPIC")
        .setProperty("YOUR_PROPERTIES")        .setValueOnlyDeserializer(ConfluentRegistryAvroDeserializationSchema.forGeneric(schema, schemaRegistryUrl, schemaProps))
        .build();

DataStreamGenericRecord kafkaDataStream = env.fromSource(source, WatermarkStrategy.noWatermarks(), "Kafka Source");

kafkaDataStream.print();