Skip to content
Advertisement

Is there a need of seperate Key Schema(other than a schema for fields) while writing Avro producer?

I am writing Java Avro Producer code for my project. I have registered an Avro schema for all the fields which need to be passed.

My Registered Schema-

{

“name”: “Claim”,

“type”: “record”,

“namespace”: “com.schema.avro”,

“fields”: [

{

  "name": "icn",

  "type": "string"

},

{

  "name": "fln,

  "type": "int"

},

]

}

I am using “icn” field value as a key but I don’t have a key schema registered separately. I am not sure if that is required.

i) Can I directly use a field already in my current schema(“icn” in this case) as the key without having to register a key schema?

ii) Do I need to register the key schema separately? If so, is that part of the schema already created for fields or is it different?

Advertisement

Answer

You are not required to use avro for keys. If your key is of type string you may use org.apache.kafka.common.serialization.StringSerializer. If you want to use avro, you need to register the schema for each object type.

Advertisement