Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Avro schema in schema registry

I am using Confluent's JDBC connector to send data into Kafka in the Avro format. I need to store this schema in the schema registry, but I'm not sure what format it accepts. I've read the documentation here, but it doesn't mention much.

I have tried this (taking the Avro output and pasting it in - for one int and one string field):

curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"     --data '{"type":"struct","fields":[{"type":"int64","optional":true,"field":"id"},{"type":"string","optional":true,"field":"serial"}],"optional":false,"name":"test"}' http://localhost:8081/subjects/view/versions

but I get the error: {"error_code":422,"message":"Unrecognized field: type"}

like image 321
skunkwerk Avatar asked Sep 14 '16 18:09

skunkwerk


1 Answers

The schema that you give as a JSON should start with a 'schema' key. The actual schema that you provide will be the value of the key schema.

So your request should look like this:

 curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json"     --data '{"schema" : "{\"type\":\"string\",\"fields\":[{\"type\":\"int64\",\"optional\":true,\"field\":\"id\"},{\"type\":\"string\",\"optional\":true,\"field\":\"serial\"}],\"optional\":false,\"name\":\"test\"}"}' http://localhost:8081/subjects/view/versions

I've made two other changes to the command:

  • I've escaped each double quote within the value of the schema key.
  • I've changed the struct data structure to string. I'm not sure why it isn't taking complex structures though.

Check out how they've modeled the schema here, for the first POST request described in the documentation.

like image 57
blobmarley Avatar answered Dec 02 '22 07:12

blobmarley